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

Lite wheel optimization #7855

merged 61 commits into from Apr 30, 2024

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Mar 27, 2024

Description

Resolves #7853

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Mar 27, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website building...
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/8e8adcc3cbb3c875538e38b8eb151386fc081c1e/gradio-4.28.3-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@8e8adcc3cbb3c875538e38b8eb151386fc081c1e#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Mar 27, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/app minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Lite wheel optimization

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@whitphx whitphx force-pushed the lite-wheel-contents-optimization branch 8 times, most recently from 153384f to aef053f Compare March 27, 2024 11:34
@whitphx
Copy link
Member Author

whitphx commented Mar 27, 2024

Found that this step triggers building the package, including copying _frontend_code

- name: Install test dependencies
if: inputs.test == 'true' && steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
. ${{ env.VENV_ACTIVATE }}
python -m pip install -r test/requirements.txt
python -m pip install -r client/python/test/requirements.txt

and these are needed by js/_website/generate_jsons/generate.py that follows.

@whitphx
Copy link
Member Author

whitphx commented Mar 27, 2024

Now I think ignoring the tool.hatch.build.artifacts config in pyproject.toml somehow would be the simplest path, but don't know how...

@whitphx whitphx force-pushed the lite-wheel-contents-optimization branch 3 times, most recently from 40f7248 to 571823b Compare March 29, 2024 05:50
@whitphx
Copy link
Member Author

whitphx commented Mar 29, 2024

The functional test failed because this hatch started to be needed.
I confirmed it would be working after merged into main. Ref: 571823b, https://github.com/gradio-app/gradio/actions/runs/8477748173/job/23229061320?pr=7855

pnpm --filter @gradio/client --filter @gradio/lite build
- name: Package Lite NPM package
Copy link
Member Author

Choose a reason for hiding this comment

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

It might be better if the NPM package created in this step will be published in the following step as it's guaranteed that the NPM-published file is exactly same as what we can check from the uploaded artifacts?

Copy link
Member

Choose a reason for hiding this comment

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

Aren't we already building part of this in the install-deps workflow above?

We should keep the builds together where possible, I think moving this tot he install deps action would make the most sense. Then we can have access to these assets in a variety of workflows if needed.

Copy link
Member Author

@whitphx whitphx Apr 1, 2024

Choose a reason for hiding this comment

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

You mean we should move pnpm pack to this part building Lite in the install-frontend-deps ?
(Is it ok that the "install-*-deps" action is also responsible for building and packaging things which sounds not intuitive? ah, ok, the "deps" here includes js/* packages which need to be built per run)

- name: Build frontend lite
if: inputs.build_lite == 'true'
shell: bash
run: |
. venv/bin/activate
python -m pip install build
pnpm --filter @gradio/app build:lite

@@ -3,6 +3,9 @@ on:
push:
branches:
- main
pull_request:
Copy link
Member Author

@whitphx whitphx Mar 29, 2024

Choose a reason for hiding this comment

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

@pngwn Do you think it's ok to run this workflow on each PR as we discussed (while it's now failing as https://github.com/gradio-app/gradio/actions/runs/8477858436/job/23229330151?pr=7855)?

Copy link
Member

Choose a reason for hiding this comment

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

No, we can only run the publish when we want to trigger the publish workflow, this will also fail for third part contributions as they won't have access to secrets. We need to expose the assets in one of the other workflows, the deploy space workflow is probably the most appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to expose the assets in one of the other workflows, the deploy space workflow is probably the most appropriate.

OK, so you mean

  1. to move pnpm pack to the install-deps action
  2. and to use it from deploy-spaces workflow then expose the artifacts
    ?
    (Same question: is it ok to add such steps to the deploy-space workflow without renaming it?)

Copy link
Member

Choose a reason for hiding this comment

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

Yep. And yeah it's fine to add it to the deploy space workflow without renaming.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, so I applied the changes but pnpm pack is not added to the install-deps action as it's now only needed in one place.

@abidlabs
Copy link
Member

@whitphx is this ready to be reviewed or still a draft?

@whitphx whitphx marked this pull request as ready for review March 31, 2024 05:44
@whitphx
Copy link
Member Author

whitphx commented Mar 31, 2024

@abidlabs Oh yes it's to be reviewed thanks, but not ready to merge: I want opinions about the comments above.

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Left a few comments that we need to address before we can merge this.

@@ -3,6 +3,9 @@ on:
push:
branches:
- main
pull_request:
Copy link
Member

Choose a reason for hiding this comment

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

No, we can only run the publish when we want to trigger the publish workflow, this will also fail for third part contributions as they won't have access to secrets. We need to expose the assets in one of the other workflows, the deploy space workflow is probably the most appropriate.

pnpm --filter @gradio/client --filter @gradio/lite build
- name: Package Lite NPM package
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we already building part of this in the install-deps workflow above?

We should keep the builds together where possible, I think moving this tot he install deps action would make the most sense. Then we can have access to these assets in a variety of workflows if needed.

@whitphx whitphx force-pushed the lite-wheel-contents-optimization branch 3 times, most recently from 06f4313 to 7b21225 Compare April 1, 2024 07:42
@whitphx whitphx requested a review from pngwn April 1, 2024 08:29
@whitphx whitphx force-pushed the lite-wheel-contents-optimization branch from eb89816 to 4a4f18d Compare April 25, 2024 07:51
@whitphx whitphx enabled auto-merge (squash) April 25, 2024 08:51
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

Looks good to merge @whitphx !

@whitphx whitphx force-pushed the lite-wheel-contents-optimization branch from 650d9bd to d1c006e Compare April 26, 2024 01:36
@whitphx
Copy link
Member Author

whitphx commented Apr 26, 2024

@pngwn Can you approve this PR if you are ok because the merge is blocked?

…loy-spaces workflow so the frontend is built in it and frontend build is removed from the 'Build pr package' step
…ploy-spaces because they are done in the install-all-deps action
@whitphx
Copy link
Member Author

whitphx commented Apr 30, 2024

Removed some steps from the deploy-spaces workflow as the same steps are done in the install-all-deps action, as @pngwn suggested.
Looks like the workflow ran correctly: https://github.com/gradio-app/gradio/actions/runs/8887216886/job/24402132060

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks @whitphx! Sorry for all the back and forth on this one!

@whitphx whitphx merged commit 611c927 into main Apr 30, 2024
7 of 8 checks passed
@whitphx whitphx deleted the lite-wheel-contents-optimization branch April 30, 2024 03:18
@pngwn pngwn mentioned this pull request Apr 30, 2024
dawoodkhan82 pushed a commit that referenced this pull request May 6, 2024
* 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 e15fef2.

* Build the gradio wheel with the custom lite target

* add changeset

* Revert "[WIP] Show gradio files"

This reverts commit aef053f.

* Revert "Skip the copy_frontend.py hook in the Lite build"

This reverts commit ca296d0.

* 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 571823b.

* 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 fe4e1c8.

* Remove dependencies for lite build

* [TMP] Change the branch of action files

* Revert "Remove dependencies for lite build"

This reverts commit 856a858.

* 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 910b6bb.

* 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 8aa77c8.

* Fix hook name

* Revert "Set packaging version as >=23.2 in requirements.txt"

This reverts commit fbd605c.

* Revert "Revert the changes on pip install"

This reverts commit 81ff38a.

* Add comments

* Revert "[TMP] Change the branch of action files"

This reverts commit 0d6aa48.

* 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 commit 4a4f18d.

* Revert "[TMP] Trigger CI based on this PR"

This reverts commit 6cea830.

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize the wheel file contents for Lite
5 participants