-
Notifications
You must be signed in to change notification settings - Fork 33
[trainer] refactor: code refactor for diffusion training #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9847246
refactor diffusion training
zhtmike d38b646
Merge branch 'main' into diffusion_refactor
zhtmike 3b2e38a
fix
zhtmike e17c795
update project.toml
zhtmike dd268dd
add CI workflows: sanity, type-coverage-check, doc, check-pr-title
zhtmike 5cfddff
add PR template
zhtmike 225f1b8
Update tests/special_sanity/check_pr_title.py
zhtmike b571d42
sync allowed_modules in check_pr_title.py with PR template
zhtmike ca3e88b
add UT
zhtmike 93de931
drop doc.yml
zhtmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| ### What does this PR do? | ||
|
|
||
| > Add **concise** overview of what this PR aims to achieve or accomplish. Reference related GitHub issues and PRs that help with the review. | ||
|
|
||
| ### Checklist Before Starting | ||
|
|
||
| - [ ] Search for similar PRs. Paste at least one query link here: ... | ||
| - [ ] Format the PR title as `[{modules}] {type}: {description}` (This will be checked by the CI) | ||
| - `{modules}` include `fsdp`, `vllm_omni`, `rollout`, `trainer`, `ci`, `training_utils`, `recipe`, `ray`, `worker`, `single_controller`, `misc`, `perf`, `model`, `algo`, `env`, `tool`, `ckpt`, `doc`, `data`, `cfg`, `reward`, `diffusion`, `omni`, `tests`, `docker` | ||
| - If this PR involves multiple modules, separate them with `,` like `[diffusion, doc]` | ||
| - `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test` | ||
| - If this PR breaks any API (CLI arguments, config, function signature, etc.), add `[BREAKING]` to the beginning of the title. | ||
| - Example: `[BREAKING][diffusion, fsdp] feat: new rollout scheduler` | ||
|
|
||
| ### Test | ||
|
|
||
| > For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc. | ||
|
|
||
| ### API and Usage Example | ||
|
|
||
| > Demonstrate how the API changes if any, and provide usage example(s) if possible. | ||
|
|
||
| ```python | ||
| # Add code snippet or script demonstrating how to use this | ||
| ``` | ||
|
|
||
| ### Design & Code Changes | ||
|
|
||
| > Demonstrate the high-level design if this PR is complex, and list the specific changes. | ||
|
|
||
| ### Checklist Before Submitting | ||
|
|
||
| > [!IMPORTANT] | ||
| > Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review. | ||
|
|
||
| - [ ] Read the [Contribute Guide](https://github.com/verl-project/verl-omni/blob/main/CONTRIBUTING.md). | ||
| - [ ] Apply [pre-commit checks](https://github.com/verl-project/verl-omni/blob/main/CONTRIBUTING.md#code-linting-and-formatting): `pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always` | ||
| - [ ] Add / Update the documentation. | ||
| - [ ] Add unit or end-to-end test(s) to [the CI workflow](https://github.com/verl-project/verl-omni/tree/main/.github/workflows) to cover all the code. If not feasible, explain why: ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| on: | ||
| pull_request: | ||
| types: [opened, edited, synchronize] | ||
|
|
||
| jobs: | ||
| check-title: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Run PR title checker | ||
| run: python3 tests/special_sanity/check_pr_title.py | ||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
|
|
||
| - name: Run PR description checker | ||
| run: python3 tests/special_sanity/check_pr_description.py | ||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| GITHUB_EVENT_PATH: ${{ github.event_path }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: sanity | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "**/*.py" | ||
| - .github/workflows/sanity.yml | ||
| - "tests/special_sanity/**" | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| sanity: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.10"] | ||
| steps: | ||
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install the current repository | ||
| run: | | ||
| pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu | ||
| pip3 install -r requirements.txt | ||
| pip3 install -r requirements-test.txt | ||
| pip3 install --no-deps -e . | ||
| - name: Run sanity test | ||
| run: | | ||
| pytest -s -x tests/special_sanity | ||
| - name: Assert documentation requirement for functions | ||
| run: python3 tests/special_sanity/validate_imported_docs.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Type Annotation and Docstring Coverage | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '**/*.py' | ||
| - '.github/workflows/type-coverage-check.yml' | ||
|
|
||
| jobs: | ||
| type-coverage-check: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Important: fetch full history so `origin/main` is available | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.10' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu | ||
| pip3 install -r requirements.txt | ||
| pip3 install --no-deps -e . | ||
| - name: Run type annotation coverage check | ||
| run: | | ||
| python3 tests/special_sanity/type_coverage_check.py | ||
| - name: Run docstring coverage check | ||
| run: | | ||
| python3 tests/special_sanity/check_api_docs.py verl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| drop later |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Copyright 2026 Bytedance Ltd. and/or its affiliates | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from .qwen_image import QwenImage | ||
|
|
||
| __all__ = ["QwenImage"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Copyright 2026 Bytedance Ltd. and/or its affiliates | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from .pipeline_qwenimage import QwenImagePipelineWithLogProb | ||
|
|
||
| __all__ = ["QwenImagePipelineWithLogProb"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # ------------------------------- | ||
| # build-system | ||
| # ------------------------------- | ||
| [build-system] | ||
| requires = [ | ||
| "setuptools>=61.0", | ||
| "wheel" | ||
| ] | ||
| build-backend = "setuptools.build_meta" | ||
|
|
||
| # ------------------------------- | ||
| # project (PEP 621 metadata) | ||
| # ------------------------------- | ||
| [project] | ||
| name = "verl-omni" | ||
| # We'll mark the version as "dynamic" because it's read from the file "verl/version/version" | ||
| # (PEP 621 calls this "dynamic version"). | ||
| # The actual version is specified in the [tool.setuptools.dynamic] section below. | ||
| dynamic = ["version", "dependencies", "optional-dependencies", "authors", "urls"] | ||
|
|
||
| description = "verl-omni: Easy, fast, and stable RL training for diffusion and omni-modality models" | ||
| license = {text = "Apache-2.0"} | ||
| readme = {file = "README.md", content-type = "text/markdown"} | ||
| requires-python = ">=3.10" | ||
|
|
||
| # ------------------------------- | ||
| # tool.ruff - Linting configuration | ||
| # ------------------------------- | ||
| [tool.ruff] | ||
| # Note: While the formatter will attempt to format lines such that they remain within the line-length, | ||
| # it isn't a hard upper bound, and formatted lines may exceed the line-length. | ||
| line-length = 120 | ||
| exclude = ["scripts/legacy_model_merger.py"] | ||
|
|
||
| [tool.ruff.lint] | ||
| isort = {known-first-party = ["verl"]} | ||
| # c.f. https://github.com/vllm-project/vllm/blob/ce8d6b75fc0586045df75ee1568a5b5f9957251b/pyproject.toml | ||
| select = [ | ||
| # pycodestyle | ||
| "E", | ||
| # Pyflakes | ||
| "F", | ||
| # pyupgrade | ||
| "UP", | ||
| # flake8-bugbear | ||
| "B", | ||
| # isort | ||
| "I", | ||
| "G", | ||
| ] | ||
| ignore = [ | ||
| # star imports | ||
| "F405", "F403", | ||
| # lambda expression assignment | ||
| "E731", | ||
| # Loop control variable not used within loop body | ||
| "B007", | ||
| # f-string format | ||
| "UP032", | ||
| # `.log()` statement uses f-string | ||
| "G004", | ||
| # X | None for type annotations | ||
| "UP045", | ||
| # deprecated import | ||
| "UP035", | ||
| ] | ||
|
|
||
| # ------------------------------- | ||
| # tool.mypy - typechecking config | ||
| # ------------------------------- | ||
| [tool.mypy] | ||
| pretty = true | ||
| ignore_missing_imports = true | ||
| explicit_package_bases = true | ||
| follow_imports = "skip" | ||
|
|
||
| # Blanket silence | ||
| ignore_errors = true | ||
|
|
||
| [[tool.mypy.overrides]] | ||
| module = [ | ||
| "verl.trainer.config.algorithm", | ||
| "verl.trainer.ppo.core_algos", | ||
| "verl.trainer.ppo.reward", | ||
| "verl.workers.reward_manager", | ||
| "verl.workers.reward_manager.*", | ||
| ] | ||
| ignore_errors = false | ||
|
|
||
| # ------------------------------- | ||
| # tool.setuptools - Additional config | ||
| # ------------------------------- | ||
| [tool.setuptools] | ||
| # True means `setuptools` will attempt to include all relevant files in package_data automatically. | ||
| # This corresponds to `include_package_data=True` in setup.py. | ||
| include-package-data = true | ||
|
|
||
| # We read the version from a file in 'verl/version/version' | ||
| [tool.setuptools.dynamic] | ||
| version = {file = "verl/version/version"} | ||
|
|
||
| # If you need to mimic `package_dir={'': '.'}`: | ||
| [tool.setuptools.package-dir] | ||
| "" = "." | ||
|
|
||
| # If you need to include specific non-Python data (like YAML files or version file): | ||
| # This is the rough equivalent of package_data={'': ['version/*'], 'verl': ['trainer/config/*.yaml']} | ||
| [tool.setuptools.package-data] | ||
| verl = [ | ||
| "version/*", | ||
| "trainer/config/*.yaml", | ||
| "trainer/config/*/*.yaml", | ||
| "experimental/*/config/*.yaml", | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can drop requirements* if we use pyproject.toml?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is required by sanity check CI, etc.