Skip to content

Commit 921e9d7

Browse files
committed
feat(pre-commit): configure pre-commit hooks and add setup guide
- Add .pre-commit-config.yaml with trailing-whitespace, end-of-file-fixer, check-yaml, ruff, pyink, and pylint - Update .gitignore to track .pre-commit-config.yaml - Add pre-commit setup and venv instructions to README.md
1 parent 9ca9f9b commit 921e9d7

3 files changed

Lines changed: 73 additions & 12 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ debug.env
160160
tags
161161

162162
# pre-commit
163-
.pre-commit*
163+
.pre-commit-cache/
164+
!.pre-commit-config.yaml
164165

165166
# .lock
166167
*.lock

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v5.0.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
args: ['--maxkb=5000']
12+
- id: check-merge-conflict
13+
14+
- repo: https://github.com/astral-sh/ruff-pre-commit
15+
rev: v0.9.9
16+
hooks:
17+
- id: ruff
18+
args: [--fix]
19+
20+
- repo: https://github.com/google/pyink
21+
rev: 23.10.0
22+
hooks:
23+
- id: pyink
24+
args: ["--pyink-indentation=2", "--line-length=125"]
25+
26+
- repo: local
27+
hooks:
28+
- id: pylint
29+
name: pylint
30+
entry: pylint --fail-under=7
31+
language: system
32+
types: [python]
33+
files: ^(src/maxdiffusion|end_to_end)/

README.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ After installation completes, run the training script.
181181
```bash
182182
rm $TFRECORDS_DATASET_DIR/eval_timesteps/file_42-430.tfrec
183183
```
184-
184+
185185
### Training on a Single VM
186186

187187
Loading the data is supported both locally from the disk created above, or from `gcs`. In this guide, we'll be using a gcs bucket to train. First copy the data to the GCS bucket.
@@ -266,7 +266,7 @@ After installation completes, run the training script.
266266
- per_device_batch_size can be a fractional, but must be a whole number when multiplied by number of devices. In this example, 0.25 * 4 (devices) = effective global batch size = 1.
267267
- The step time in v5p-8 with global batch size = 1 is large due to using `FULL` remat. On larger number of chips we can run larger batch sizes greatly increasing MFU, as we will see in the next session of deploying with xpk.
268268
- To enable eval during training set `eval_every` to a value > 0.
269-
- In Wan2.1, the ici_fsdp_parallelism axis is used for sequence parallelism, the ici_tensor_parallelism axis is used for head parallelism.
269+
- In Wan2.1, the ici_fsdp_parallelism axis is used for sequence parallelism, the ici_tensor_parallelism axis is used for head parallelism.
270270
- You can enable both, keeping in mind that Wan2.1 has 40 heads and 40 must be evenly divisible by ici_tensor_parallelism.
271271
- For Sequence parallelism, the code pads the sequence length to evenly divide the sequence. Try out different ici_fsdp_parallelism numbers, but we find 2 and 4 to be the best right now.
272272
- For use on GPU it is recommended to enable the cudnn_te_flash attention kernel for optimal performance.
@@ -309,7 +309,7 @@ After installation completes, run the training script.
309309
### Deploying with XPK
310310

311311
This assumes the user has already created an xpk cluster, installed all dependencies and the also created the dataset from the step above. For getting started with MaxDiffusion and xpk see [this guide](docs/getting_started/run_maxdiffusion_via_xpk.md).
312-
312+
313313
Using v5p-256 Then the command to run on xpk is as follows:
314314

315315
```bash
@@ -523,8 +523,8 @@ To generate images, run the following command:
523523
```bash
524524
python src/maxdiffusion/generate_ltx_video.py src/maxdiffusion/configs/ltx_video.yml output_dir="[SAME DIRECTORY]" config_path="src/maxdiffusion/models/ltx_video/ltxv-13B.json"
525525
```
526-
Img2video Generation:
527-
526+
Img2video Generation:
527+
528528
Add conditioning image path as conditioning_media_paths in the form of ["IMAGE_PATH"] along with other generation parameters in the ltx_video.yml file. Then follow same instruction as above.
529529

530530
## LTX-2 Video
@@ -704,14 +704,14 @@ python src/maxdiffusion/generate_wan.py \
704704
### Ring Attention
705705
We added ring attention support for Wan models. Below are the stats for one `720p` (81 frames) video generation (with CFG DP):
706706
| Accelerator | Model | Attention Type | Inference Steps | Sharding | e2e Generation Time |
707-
| -- | -- | -- | -- | -- | -- |
707+
| -- | -- | -- | -- | -- | -- |
708708
| v7x-8 | WAN 2.1 | Tokamax Flash | 50 | dp2-fsdp1-context4-tp1 | **249.3** |
709709
| v7x-8 | WAN 2.1 | Tokamax Ring | 50 | dp2-fsdp1-context4-tp1 | 252.4 |
710710
| v7x-8 | WAN 2.2 | Tokamax Flash | 40 | dp2-fsdp1-context4-tp1 | **194.4** |
711711
| v7x-8 | WAN 2.2 | Tokamax Ring | 40 | dp2-fsdp1-context4-tp1 | 201.7 |
712712

713713
| Accelerator | Model | Attention Type | Inference Steps | Sharding | e2e Generation Time |
714-
| -- | -- | -- | -- | -- | -- |
714+
| -- | -- | -- | -- | -- | -- |
715715
| v7x-16 | WAN 2.1 | Tokamax Flash | 50 | dp2-fsdp1-context8-tp1 | **127.1** |
716716
| v7x-16 | WAN 2.1 | Tokamax Ring | 50 | dp2-fsdp1-context8-tp1 | 137.2 |
717717
| v7x-16 | WAN 2.2 | Tokamax Flash | 40 | dp2-fsdp1-context8-tp1 | **106.0** |
@@ -751,7 +751,7 @@ The optimal attention tile sizes (`block_q` / `block_kv`) depend on the sequence
751751

752752
If you are using a TPU v6e (Trillium), you can use optimized flash block sizes for faster inference. Uncomment Flux-dev [config](src/maxdiffusion/configs/base_flux_dev.yml#60) and Flux-schnell [config](src/maxdiffusion/configs/base_flux_schnell.yml#68)
753753

754-
To keep text encoders, vae and transformer on HBM memory at all times, the following command shards the model across devices.
754+
To keep text encoders, vae and transformer on HBM memory at all times, the following command shards the model across devices.
755755

756756
```bash
757757
python src/maxdiffusion/generate_flux.py src/maxdiffusion/configs/base_flux_schnell.yml jax_cache_dir=/tmp/cache_dir run_name=flux_test output_dir=/tmp/ prompt="photograph of an electronics chip in the shape of a race car with trillium written on its side" per_device_batch_size=1 ici_data_parallelism=1 ici_fsdp_parallelism=-1 offload_encoders=False
@@ -900,13 +900,40 @@ MaxDiffusion started as a fork of [Diffusers](https://github.com/huggingface/dif
900900
Whether you are forking MaxDiffusion for your own needs or intending to contribute back to the community, a full suite of tests can be found in `tests` and `src/maxdiffusion/tests`.
901901
902902
To run unit tests simply run:
903-
```
903+
```bash
904904
python -m pytest
905905
```
906906
907-
This project uses `pylint` and `pyink` to enforce code style. Before submitting a pull request, please ensure your code passes these checks by running:
907+
### Pre-commit Hooks
908+
909+
We use [pre-commit](https://pre-commit.com/) to automatically check and format code before each commit (using `pyink`, `ruff`, `pylint`, and general git hygiene checks).
910+
911+
> **Important:** Make sure you are in your active virtual environment (e.g. `maxdiffusion_venv` or your active venv) before running `pre-commit install`, so that hooks run using the environment's installed dependencies.
912+
913+
```bash
914+
# 1. Activate your virtual environment first
915+
source <path-to-venv>/bin/activate
916+
917+
# 2. Install pre-commit (if not already installed)
918+
pip install pre-commit
908919
920+
# 3. Install git pre-commit hooks
921+
pre-commit install
909922
```
923+
924+
Once installed, pre-commit will automatically run on staged files whenever you run `git commit`.
925+
926+
You can also run all pre-commit checks manually across the entire repository at any time:
927+
928+
```bash
929+
pre-commit run --all-files
930+
```
931+
932+
### Code Style
933+
934+
This project uses `pylint` and `pyink` to enforce code style. Before submitting a pull request, please ensure your code passes these checks by running:
935+
936+
```bash
910937
bash code_style.sh
911938
```
912939
@@ -919,4 +946,4 @@ The full suite of -end-to end tests is in `tests` and `src/maxdiffusion/tests`.
919946
To learn how to enable ML Diagnostics and XProf profiling for your runs, please see our [ML Diagnostics Guide](docs/profiling.md).
920947
921948
## Metrics
922-
To learn how to enable ML Diagnostics metrics tracking for your runs, please see our [Metrics Guide](docs/metrics.md).
949+
To learn how to enable ML Diagnostics metrics tracking for your runs, please see our [Metrics Guide](docs/metrics.md).

0 commit comments

Comments
 (0)