mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-17 11:29:58 +08:00
Lite wheel optimization (#7855)
* Add `pull_request.branches.main` as a trigger of the `publish` workflow * [WIP] Comment out the publish steps * Package and upload the NPM package for debug * Skip the copy_frontend.py hook in the Lite build * add changeset * [WIP] Show gradio files * [WIP] Show gradio files * Comment out installing the gradio and gradio_client libraries * Restore installing gradio_client because it's used by `python js/_website/generate_jsons/generate.py` that follows * Restore installing gradio because it's used by `python js/_website/generate_jsons/generate.py` that follows * Add code * Revert "[WIP] Show gradio files" This reverts commit e15fef29bd14671576e64d94d3b844786ebe7e83. * Build the gradio wheel with the custom lite target * add changeset * Revert "[WIP] Show gradio files" This reverts commit aef053f9caad203c7e1bbfa15e9f9e536f77442a. * Revert "Skip the copy_frontend.py hook in the Lite build" This reverts commit ca296d0e4e169adbb6af3705561869aa8c9037b7. * Update .github/actions/install-frontend-deps/action.yml for hatch installation * [WIP] Fix test-functional.yml and .github/actions/install-all-deps/action.yml to call the setup actions in this branch * Revert "[WIP] Fix test-functional.yml and .github/actions/install-all-deps/action.yml to call the setup actions in this branch" This reverts commit 571823b4a05f7e41e0b3731d51c5bd86b2e17ddc. * Comment-in lines in publish.yml * Move Lite build from publish.yml to deploy-spaces.yml * Use the build_lite option of install-all-deps instead of running the build command * [TMP] Change the branch of action files * Fix the hatch Lite build setting * Return pnpm pack to deploy-space * Revert "[TMP] Change the branch of action files" This reverts commit fe4e1c8f210eb21ac7ee1bd4b219d35e1ae84c85. * Remove dependencies for lite build * [TMP] Change the branch of action files * Revert "Remove dependencies for lite build" This reverts commit 856a858c1f49d736bfeb056ba0ec7e9bc35af29c. * Install packaging>=23.2 * [TMP] Show packaging version * Fix pip install * Fix * Uninstall packaging once * Use `pip install -U` instead of uninstalling the exiting version * Revert "[TMP] Show packaging version" This reverts commit 910b6bbde3dc8777c051bd5576813913d57959f7. * Add `-U` flag * Set packaging version as >=23.2 * Revert the changes on pip install * Set packaging version as >=23.2 in requirements.txt * Revert "Set packaging version as >=23.2" This reverts commit 8aa77c8930815e69d7256886cad88b6da8361069. * Fix hook name * Revert "Set packaging version as >=23.2 in requirements.txt" This reverts commit fbd605cbfb5d06706eacc0648a2e9d7816c9de1f. * Revert "Revert the changes on pip install" This reverts commit 81ff38a660635fce9cb17862a2072e4d169c3466. * Add comments * Revert "[TMP] Change the branch of action files" This reverts commit 0d6aa48d75a842db9b3987212deffedb0c0ca51d. * Revert the trigger of .github/workflows/deploy-spaces.yml * Remove unused `node_auth_token` and `npm_token` inputs from the `install-all-deps` action * [TMP] Trigger CI based on this PR * Remove packging installation * Revert "Remove packging installation" This reverts commit4a4f18de3a
. * Revert "[TMP] Trigger CI based on this PR" This reverts commit6cea830c8e
. --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
This commit is contained in:
parent
989fe2566f
commit
611c9273a3
6
.changeset/spotty-toes-argue.md
Normal file
6
.changeset/spotty-toes-argue.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@gradio/app": minor
|
||||
"gradio": minor
|
||||
---
|
||||
|
||||
feat:Lite wheel optimization
|
33
.config/lite-builder/pyproject.toml
Normal file
33
.config/lite-builder/pyproject.toml
Normal file
@ -0,0 +1,33 @@
|
||||
[build-system]
|
||||
requires = ["hatchling",]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "lite-builder"
|
||||
description = "Python library for easily interacting with trained machine learning models"
|
||||
license = "Apache-2.0"
|
||||
version = "0.0.2"
|
||||
requires-python = ">=3.8"
|
||||
authors = [
|
||||
{ name = "Abubakar Abid", email = "gradio-team@huggingface.co" },
|
||||
{ name = "Ali Abid", email = "gradio-team@huggingface.co" },
|
||||
{ name = "Ali Abdalla", email = "gradio-team@huggingface.co" },
|
||||
{ name = "Dawood Khan", email = "gradio-team@huggingface.co" },
|
||||
{ name = "Ahsen Khaliq", email = "gradio-team@huggingface.co" },
|
||||
{ name = "Pete Allen", email = "gradio-team@huggingface.co" },
|
||||
{ name = "Ömer Faruk Özdemir", email = "gradio-team@huggingface.co" },
|
||||
{ name = "Freddy A Boulton", email = "gradio-team@huggingface.co" },
|
||||
{ name = "Hannah Blair", email = "gradio-team@huggingface.co" },
|
||||
]
|
||||
keywords = ["machine learning", "reproducibility", "visualization"]
|
||||
|
||||
classifiers = [
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
]
|
||||
|
||||
[tool.hatch.build]
|
||||
sources = ["src"]
|
||||
only-packages = true
|
||||
|
||||
[project.entry-points.hatch]
|
||||
lite_builder = "lite_builder.hooks"
|
0
.config/lite-builder/src/lite_builder/__init__.py
Normal file
0
.config/lite-builder/src/lite_builder/__init__.py
Normal file
5
.config/lite-builder/src/lite_builder/builder.py
Normal file
5
.config/lite-builder/src/lite_builder/builder.py
Normal file
@ -0,0 +1,5 @@
|
||||
from hatchling.builders.wheel import WheelBuilder
|
||||
|
||||
|
||||
class LiteBuilder(WheelBuilder):
|
||||
PLUGIN_NAME = 'lite'
|
6
.config/lite-builder/src/lite_builder/hooks.py
Normal file
6
.config/lite-builder/src/lite_builder/hooks.py
Normal file
@ -0,0 +1,6 @@
|
||||
from hatchling.plugin import hookimpl
|
||||
from .builder import LiteBuilder
|
||||
|
||||
@hookimpl
|
||||
def hatch_register_builder():
|
||||
return LiteBuilder
|
12
.github/actions/install-all-deps/action.yml
vendored
12
.github/actions/install-all-deps/action.yml
vendored
@ -2,15 +2,9 @@ name: 'install all deps'
|
||||
description: 'Install all deps'
|
||||
|
||||
inputs:
|
||||
always_install_pnpm:
|
||||
always_install_pnpm:
|
||||
description: 'Dictates whether or not we should install pnpm & dependencies, regardless of the cache'
|
||||
default: 'false'
|
||||
node_auth_token:
|
||||
description: 'Node auth token'
|
||||
default: ""
|
||||
npm_token:
|
||||
description: 'npm token'
|
||||
default: ""
|
||||
skip_build:
|
||||
description: 'Skip build'
|
||||
default: 'false'
|
||||
@ -85,14 +79,12 @@ runs:
|
||||
shell: bash
|
||||
run: |
|
||||
. ${{ env.VENV_ACTIVATE }}
|
||||
python -m pip install -e client/python
|
||||
python -m pip install -e client/python
|
||||
python -m pip install -e ".[oauth]"
|
||||
- name: install-frontend
|
||||
uses: "gradio-app/gradio/.github/actions/install-frontend-deps@main"
|
||||
with:
|
||||
always_install_pnpm: ${{ inputs.always_install_pnpm }}
|
||||
node_auth_token: ${{ inputs.node_auth_token }}
|
||||
npm_token: ${{ inputs.npm_token }}
|
||||
skip_build: ${{ inputs.skip_build }}
|
||||
build_lite: ${{ inputs.build_lite }}
|
||||
- name: generate json
|
||||
|
13
.github/actions/install-frontend-deps/action.yml
vendored
13
.github/actions/install-frontend-deps/action.yml
vendored
@ -5,21 +5,12 @@ inputs:
|
||||
always_install_pnpm:
|
||||
description: 'Dictates whether or not we should install pnpm & dependencies, regardless of the cache'
|
||||
default: 'false'
|
||||
node_auth_token:
|
||||
description: 'Node auth token'
|
||||
default: ""
|
||||
npm_token:
|
||||
description: 'npm token'
|
||||
default: ""
|
||||
skip_build:
|
||||
description: 'Skip build'
|
||||
default: 'false'
|
||||
build_lite:
|
||||
description: 'Build lite'
|
||||
default: 'false'
|
||||
os:
|
||||
description: 'OS'
|
||||
default: 'ubuntu-latest'
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
@ -56,5 +47,5 @@ runs:
|
||||
shell: bash
|
||||
run: |
|
||||
. venv/bin/activate
|
||||
python -m pip install build
|
||||
pnpm --filter @gradio/app build:lite
|
||||
python -m pip install -U build hatch packaging>=23.2 # packaging>=23.2 is needed to build Lite due to https://github.com/pypa/hatch/issues/1381
|
||||
pnpm --filter @gradio/app build:lite
|
||||
|
40
.github/workflows/deploy-spaces.yml
vendored
40
.github/workflows/deploy-spaces.yml
vendored
@ -4,7 +4,7 @@ on:
|
||||
workflow_dispatch:
|
||||
workflow_run:
|
||||
workflows: ["trigger"]
|
||||
types:
|
||||
types:
|
||||
- requested
|
||||
|
||||
permissions:
|
||||
@ -12,7 +12,7 @@ permissions:
|
||||
concurrency:
|
||||
group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
|
||||
cancel-in-progress: true
|
||||
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
name: "changes"
|
||||
@ -35,7 +35,7 @@ jobs:
|
||||
name: "deploy / spaces"
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
commit_status: false
|
||||
|
||||
|
||||
comment-spaces-start:
|
||||
needs: changes
|
||||
uses: "./.github/workflows/comment-queue.yml"
|
||||
@ -57,19 +57,23 @@ jobs:
|
||||
with:
|
||||
ref: ${{ needs.changes.outputs.merge_sha }}
|
||||
repository: ${{ needs.changes.outputs.mergeable == 'true' && github.repository || needs.changes.outputs.source_repo }}
|
||||
- name: Install Python
|
||||
uses: actions/setup-python@v5
|
||||
|
||||
- name: install dependencies
|
||||
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
|
||||
with:
|
||||
python-version: '3.9'
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
always_install_pnpm: true
|
||||
python_version: '3.9'
|
||||
build_lite: 'true'
|
||||
|
||||
- name: Package Lite NPM package
|
||||
working-directory: js/lite
|
||||
run: pnpm pack --pack-destination .
|
||||
- name: Upload Lite NPM package
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
version: 8.15
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18
|
||||
cache: pnpm
|
||||
cache-dependency-path: pnpm-lock.yaml
|
||||
name: gradio-lite-${{ github.sha }}
|
||||
path: js/lite/gradio-lite-*.tgz
|
||||
|
||||
- name: Install pip
|
||||
run: python -m pip install build requests
|
||||
- name: Get Gradio Version
|
||||
@ -78,17 +82,13 @@ jobs:
|
||||
if ${{ github.event_name == 'pull_request' || github.event.workflow_run.event == 'pull_request' }}; then
|
||||
echo "GRADIO_VERSION=$(python -c 'import requests;print(requests.get("https://pypi.org/pypi/gradio/json").json()["info"]["version"])')" >> $GITHUB_OUTPUT
|
||||
python -c "import os;print(os.environ['GITHUB_REF'].split('/')[2])" > pr_number.txt
|
||||
else
|
||||
else
|
||||
echo "GRADIO_VERSION=$(python -c 'import json; print(json.load(open("gradio/package.json"))["version"])')" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- name: Build pr package
|
||||
run: |
|
||||
python -c 'import json; j = json.load(open("gradio/package.json")); j["version"] = "${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}"; json.dump(j, open("gradio/package.json", "w"))'
|
||||
pnpm i --frozen-lockfile --ignore-scripts
|
||||
pnpm build
|
||||
python3 -m build -w
|
||||
env:
|
||||
NODE_OPTIONS: --max_old_space_size=8192
|
||||
|
||||
- name: Set up Demos
|
||||
run: |
|
||||
@ -123,7 +123,7 @@ jobs:
|
||||
run: |
|
||||
echo ${{github.event.workflow_run.event }}
|
||||
echo ${{ github.event.workflow_run.conclusion }}
|
||||
|
||||
|
||||
comment-spaces-success:
|
||||
uses: "./.github/workflows/comment-queue.yml"
|
||||
needs: [deploy-spaces, changes]
|
||||
|
22
.github/workflows/publish.yml
vendored
22
.github/workflows/publish.yml
vendored
@ -21,13 +21,11 @@ jobs:
|
||||
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
|
||||
with:
|
||||
always_install_pnpm: true
|
||||
node_auth_token: ${{ secrets.NPM_TOKEN }}
|
||||
npm_token: ${{ secrets.NPM_TOKEN }}
|
||||
skip_build: 'false'
|
||||
- name: Build packages
|
||||
run: |
|
||||
run: |
|
||||
. venv/bin/activate
|
||||
pip install build
|
||||
pip install -U build hatch packaging>=23.2 # packaging>=23.2 is needed to build Lite due to https://github.com/pypa/hatch/issues/1381
|
||||
pnpm --filter @gradio/client --filter @gradio/lite --filter @gradio/preview build
|
||||
- name: create and publish versions
|
||||
id: changesets
|
||||
@ -43,26 +41,26 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
|
||||
- name: add label to skip chromatic build
|
||||
if: ${{ steps.changesets.outputs.pullRequestNumber != '' && steps.changesets.outputs.pullRequestNumber != 'undefined' }}
|
||||
run: gh pr edit "$PR_NUMBER" --add-label "no-visual-update"
|
||||
run: gh pr edit "$PR_NUMBER" --add-label "no-visual-update"
|
||||
env:
|
||||
PR_NUMBER: ${{ steps.changesets.outputs.pullRequestNumber }}
|
||||
GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
|
||||
GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
|
||||
- name: add label to run flaky tests
|
||||
if: ${{ steps.changesets.outputs.pullRequestNumber != '' && steps.changesets.outputs.pullRequestNumber != 'undefined' }}
|
||||
run: gh pr edit "$PR_NUMBER" --add-label "flaky-tests"
|
||||
run: gh pr edit "$PR_NUMBER" --add-label "flaky-tests"
|
||||
env:
|
||||
PR_NUMBER: ${{ steps.changesets.outputs.pullRequestNumber }}
|
||||
GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
|
||||
GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
|
||||
- name: add label to run backend tests on Windows
|
||||
if: ${{ steps.changesets.outputs.pullRequestNumber != '' && steps.changesets.outputs.pullRequestNumber != 'undefined' }}
|
||||
run: gh pr edit "$PR_NUMBER" --add-label "windows-tests"
|
||||
run: gh pr edit "$PR_NUMBER" --add-label "windows-tests"
|
||||
env:
|
||||
PR_NUMBER: ${{ steps.changesets.outputs.pullRequestNumber }}
|
||||
GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
|
||||
GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
|
||||
- name: publish to pypi
|
||||
if: steps.changesets.outputs.hasChangesets != 'true'
|
||||
uses: "gradio-app/github/actions/publish-pypi@main"
|
||||
env:
|
||||
env:
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWSACCESSKEYID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWSSECRETKEY }}
|
||||
AWS_DEFAULT_REGION: us-west-2
|
||||
@ -72,6 +70,6 @@ jobs:
|
||||
gradio:${{ secrets.PYPI_API_TOKEN }}
|
||||
gradio_client:${{ secrets.PYPI_GRADIO_CLIENT_TOKEN }}
|
||||
- name: trigger spaces deploy workflow
|
||||
env:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.COMMENT_TOKEN }}
|
||||
run: gh workflow run deploy-spaces.yml
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
||||
.eggs/
|
||||
gradio.egg-info
|
||||
dist/
|
||||
dist-lite/
|
||||
*.pyc
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
@ -10,7 +10,7 @@
|
||||
"dev:lite:worker": "pnpm --filter @gradio/wasm dev",
|
||||
"build": "vite build --mode production --emptyOutDir",
|
||||
"cssbuild": "python ../../scripts/generate_theme.py --outfile ./src/lite/theme.css",
|
||||
"pybuild:gradio": "cd ../../ && python -m build",
|
||||
"pybuild:gradio": "python -m pip install -U hatch packaging>=23.2 && cd ../../ && hatch build -t lite",
|
||||
"pybuild:gradio-client": "cd ../../client/python && python -m build",
|
||||
"pybuild": "run-p pybuild:*",
|
||||
"build:lite": "pnpm pybuild && pnpm cssbuild && pnpm --filter @gradio/client build && pnpm --filter @gradio/wasm build && vite build --mode production:lite",
|
||||
|
@ -185,7 +185,7 @@ export default defineConfig(({ mode }) => {
|
||||
// For the Wasm app to import the wheel file URLs.
|
||||
"gradio.whl": resolve(
|
||||
__dirname,
|
||||
`../../dist/gradio-${version_raw}-py3-none-any.whl`
|
||||
`../../dist-lite/gradio-${version_raw}-py3-none-any.whl`
|
||||
),
|
||||
"gradio_client.whl": resolve(
|
||||
__dirname,
|
||||
|
@ -78,6 +78,11 @@ artifacts = [
|
||||
"py.typed",
|
||||
]
|
||||
|
||||
[tool.hatch.build.targets.lite]
|
||||
artifacts = ["!gradio/templates", "!*.pyi", "!/gradio/test_data", "!/gradio/_frontend_code", "!/gradio/node"]
|
||||
directory = "dist-lite"
|
||||
dependencies = ["lite-builder @ {root:uri}/../.config/lite-builder"]
|
||||
|
||||
[tool.hatch.build.targets.wheel.hooks.custom]
|
||||
path = ".config/copy_frontend.py"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user