Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lite wheel optimization #7855

Merged
merged 61 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
54ea895
Add `pull_request.branches.main` as a trigger of the `publish` workflow
whitphx Mar 27, 2024
aa0062e
[WIP] Comment out the publish steps
whitphx Mar 27, 2024
2e499bd
Package and upload the NPM package for debug
whitphx Mar 27, 2024
0a1d588
Skip the copy_frontend.py hook in the Lite build
whitphx Mar 27, 2024
9d3dcaa
add changeset
gradio-pr-bot Mar 27, 2024
ddc5675
[WIP] Show gradio files
whitphx Mar 27, 2024
0edd7ed
[WIP] Show gradio files
whitphx Mar 27, 2024
bddcb96
Comment out installing the gradio and gradio_client libraries
whitphx Mar 27, 2024
8bf58cd
Restore installing gradio_client because it's used by `python js/_web…
whitphx Mar 27, 2024
aaa5b95
Restore installing gradio because it's used by `python js/_website/ge…
whitphx Mar 27, 2024
8a1d74a
Add code
freddyaboulton Mar 27, 2024
e204ec3
Revert "[WIP] Show gradio files"
whitphx Mar 28, 2024
a3999ae
Build the gradio wheel with the custom lite target
whitphx Mar 28, 2024
cedeac0
add changeset
gradio-pr-bot Mar 28, 2024
24f3afd
Revert "[WIP] Show gradio files"
whitphx Mar 28, 2024
00df92c
Revert "Skip the copy_frontend.py hook in the Lite build"
whitphx Mar 28, 2024
fca5ac0
Update .github/actions/install-frontend-deps/action.yml for hatch ins…
whitphx Mar 28, 2024
ab30b21
[WIP] Fix test-functional.yml and .github/actions/install-all-deps/ac…
whitphx Mar 28, 2024
8475f6c
Revert "[WIP] Fix test-functional.yml and .github/actions/install-all…
whitphx Mar 29, 2024
f34eedb
Comment-in lines in publish.yml
whitphx Mar 29, 2024
b6355cc
Move Lite build from publish.yml to deploy-spaces.yml
whitphx Apr 1, 2024
70923dc
Use the build_lite option of install-all-deps instead of running the …
whitphx Apr 1, 2024
b9cfd77
[TMP] Change the branch of action files
whitphx Apr 1, 2024
d45985d
Fix the hatch Lite build setting
whitphx Apr 1, 2024
1713eef
Return pnpm pack to deploy-space
whitphx Apr 1, 2024
1a0295f
Revert "[TMP] Change the branch of action files"
whitphx Apr 1, 2024
cb336d7
Remove dependencies for lite build
whitphx Apr 4, 2024
33e03cd
[TMP] Change the branch of action files
whitphx Apr 1, 2024
f509e3c
Revert "Remove dependencies for lite build"
whitphx Apr 4, 2024
353c8b5
Install packaging>=23.2
whitphx Apr 11, 2024
5371473
[TMP] Show packaging version
whitphx Apr 11, 2024
c7c8e52
Fix pip install
whitphx Apr 11, 2024
254a4dc
Fix
whitphx Apr 11, 2024
24296a9
Uninstall packaging once
whitphx Apr 11, 2024
fd9f834
Use `pip install -U` instead of uninstalling the exiting version
whitphx Apr 11, 2024
3f6156e
Revert "[TMP] Show packaging version"
whitphx Apr 11, 2024
aa08814
Add `-U` flag
whitphx Apr 11, 2024
128e63e
Set packaging version as >=23.2
whitphx Apr 11, 2024
0d588c8
Revert the changes on pip install
whitphx Apr 11, 2024
bd35f95
Set packaging version as >=23.2 in requirements.txt
whitphx Apr 11, 2024
ef514d5
Revert "Set packaging version as >=23.2"
whitphx Apr 11, 2024
c6f9c08
Fix hook name
whitphx Apr 12, 2024
9066f0f
Revert "Set packaging version as >=23.2 in requirements.txt"
whitphx Apr 12, 2024
9b3fa04
Revert "Revert the changes on pip install"
whitphx Apr 12, 2024
61a4fc3
Add comments
whitphx Apr 12, 2024
de49e37
Revert "[TMP] Change the branch of action files"
whitphx Apr 12, 2024
59fa334
Revert the trigger of .github/workflows/deploy-spaces.yml
whitphx Apr 12, 2024
43f9e88
Remove unused `node_auth_token` and `npm_token` inputs from the `inst…
whitphx Apr 25, 2024
6cea830
[TMP] Trigger CI based on this PR
whitphx Apr 25, 2024
4a4f18d
Remove packging installation
whitphx Apr 25, 2024
858c603
Revert "Remove packging installation"
whitphx Apr 25, 2024
ea119f1
Revert "[TMP] Trigger CI based on this PR"
whitphx Apr 25, 2024
22b3e8f
Merge branch 'main' into lite-wheel-contents-optimization
whitphx Apr 25, 2024
d1c006e
Add hatch installation to the pybuild command
whitphx Apr 26, 2024
a20eed7
Revert "Add hatch installation to the pybuild command"
whitphx Apr 26, 2024
08fcbd6
Merge branch 'main' into lite-wheel-contents-optimization
whitphx Apr 29, 2024
ab1954a
Remove 'skip_build: true' from the install-all-deps action in the dep…
whitphx Apr 30, 2024
c812b12
[TMP] Trigger CI based on this PR
whitphx Apr 25, 2024
3f9c2a6
Remove 'Install Python', 'Install pnpm', and setup-node steps from de…
whitphx Apr 30, 2024
711a442
Revert "[TMP] Trigger CI based on this PR"
whitphx Apr 30, 2024
8e8adcc
Update pybuild:gradio command temporarily to make the functional test…
whitphx Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/spotty-toes-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/app": minor
"gradio": minor
---

feat:Lite wheel optimization
33 changes: 33 additions & 0 deletions .config/lite-builder/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Empty file.
5 changes: 5 additions & 0 deletions .config/lite-builder/src/lite_builder/builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from hatchling.builders.wheel import WheelBuilder


class LiteBuilder(WheelBuilder):
PLUGIN_NAME = 'lite'
6 changes: 6 additions & 0 deletions .config/lite-builder/src/lite_builder/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from hatchling.plugin import hookimpl
from .builder import LiteBuilder

@hookimpl
def hatch_register_builder():
return LiteBuilder
12 changes: 2 additions & 10 deletions .github/actions/install-all-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions .github/actions/install-frontend-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node_auth_token and npm_token get passed in the install-all-deps action. We would need to remove them there too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops missed them, thanks!

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"
Expand Down Expand Up @@ -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 changes: 20 additions & 20 deletions .github/workflows/deploy-spaces.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ on:
workflow_dispatch:
workflow_run:
workflows: ["trigger"]
types:
types:
- requested

permissions:
statuses: write
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"
Expand All @@ -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"
Expand All @@ -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
with:
python-version: '3.9'
- name: Install pnpm
uses: pnpm/action-setup@v2

- name: install dependencies
uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
with:
version: 8.15
- uses: actions/setup-node@v4
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:
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
Expand All @@ -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: |
Expand Down Expand Up @@ -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]
Expand Down
22 changes: 10 additions & 12 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
whitphx marked this conversation as resolved.
Show resolved Hide resolved
pnpm --filter @gradio/client --filter @gradio/lite --filter @gradio/preview build
- name: create and publish versions
id: changesets
Expand All @@ -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
Expand All @@ -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 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.eggs/
gradio.egg-info
dist/
dist-lite/
*.pyc
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion js/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion js/app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down