You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore: configure pre-commit hooks and format repository
- Add .pre-commit-config.yaml with trailing-whitespace, end-of-file-fixer, check-yaml, ruff, pyink, and pylint
- Fix duplicate keys in base_xl.yml, base21.yml, and ltx2_video.yml
- Update .gitignore to track .pre-commit-config.yaml
- Format files and fix end of file newlines across the repository
- Add pre-commit setup and venv instructions to README.md
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.
266
266
- 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.
267
267
- 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.
268
268
- 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.
270
270
- You can enable both, keeping in mind that Wan2.1 has 40 heads and 40 must be evenly divisible by ici_tensor_parallelism.
271
271
- 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.
272
272
- 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.
309
309
### Deploying with XPK
310
310
311
311
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
+
313
313
Using v5p-256 Then the command to run on xpk is as follows:
314
314
315
315
```bash
@@ -523,8 +523,8 @@ To generate images, run the following command:
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.
@@ -751,7 +751,7 @@ The optimal attention tile sizes (`block_q` / `block_kv`) depend on the sequence
751
751
752
752
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)
753
753
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.
755
755
756
756
```bash
757
757
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
900
900
Whether you are forking MaxDiffusion foryour own needs or intending to contribute back to the community, a full suite of tests can be foundin`tests` and `src/maxdiffusion/tests`.
901
901
902
902
To run unit tests simply run:
903
-
```
903
+
```bash
904
904
python -m pytest
905
905
```
906
906
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
908
919
920
+
# 3. Install git pre-commit hooks
921
+
pre-commit install
909
922
```
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
910
937
bash code_style.sh
911
938
```
912
939
@@ -919,4 +946,4 @@ The full suite of -end-to end tests is in `tests` and `src/maxdiffusion/tests`.
919
946
To learn how to enable ML Diagnostics and XProf profiling for your runs, please see our [ML Diagnostics Guide](docs/profiling.md).
920
947
921
948
## 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).
Copy file name to clipboardExpand all lines: docs/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ This folder contains documentation for getting started with and using MaxDiffusi
14
14
15
15
## Training
16
16
17
-
***[Common Training Guide](train_README.md)** - Provides a comprehensive guide to training MaxDiffusion models, including script usage, configuration options, and sharding strategies.
17
+
***[Common Training Guide](train_README.md)** - Provides a comprehensive guide to training MaxDiffusion models, including script usage, configuration options, and sharding strategies.
Copy file name to clipboardExpand all lines: docs/attention_blocks_flowchart.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
- "block_q": Block sizes (HBM TO VMEM and VREG) to tile along Q sequence in forward pass
5
5
- "block_kv_compute" : Sub Block size (VMEM to VREG) of "block_kv" where compute is performed in forward pass. It must be factor or same as "block_kv"
6
6
- "block_kv" : Block sizes (HBM TO VMEM) to tile along KV sequence in forward pass
7
-
- "block_q_dkv" : Block sizes along Q sequence in backward pass with fused kernel to compute gradient of q, k , v. It must be factor or same as block_q
7
+
- "block_q_dkv" : Block sizes along Q sequence in backward pass with fused kernel to compute gradient of q, k , v. It must be factor or same as block_q
8
8
- "block_kv_dkv" : Block sizes along KV sequence in backward pass. It must be factor or same as block_kv
9
9
- "block_kv_dkv_compute" : Sub Block Sizes of block_kv_dkv, must be factor or same as "block_kv_dkv"
10
10
- "block_q_dq" : Block sizes along Q sequence in backward pass with unfused kernel to compute gradient of just q. it must be factor or same as "block_q"
@@ -13,18 +13,18 @@
13
13
14
14
## Flowchart
15
15
16
-
Maxdiffusion automatically adheres to this flowchart to ensure working, and there is a log that will inform you on the modifications that maxdiffusion makes to the specified block sizes.
16
+
Maxdiffusion automatically adheres to this flowchart to ensure working, and there is a log that will inform you on the modifications that maxdiffusion makes to the specified block sizes.
17
17
18
18

19
19
20
20
> "tokamax_flash" uses the splash attention implementation in [tokamax-repo](https://github.com/openxla/tokamax/blob/main/tokamax/_src/ops/experimental/tpu/splash_attention/splash_attention_kernel.py) This kernel only supports fused backward pass where gradients for q,k,v are computed in a single kernel so "block_q_dq" and "block_kv_dq" are not used
21
21
22
22
## How block sizes matter for perfomance and accuracy
23
23
24
-
Block sizes key to saturating HBM bandwidth and ensuring maximum possible overlap of computation on cores with HBM use and VMEM to VREG. It is highly recommended to tune them.
24
+
Block sizes key to saturating HBM bandwidth and ensuring maximum possible overlap of computation on cores with HBM use and VMEM to VREG. It is highly recommended to tune them.
25
25
26
26
Block sizes also have an effect on the sequence length. Sequence length is multiple of resolution and number of frames (video), along with VAE scale down factors and patchifying ratios. This sequence length or shard of this sequence length needs to be multiple of the block sizes specified. Therefore maxdiffusion pads the sequence lengths to the nearest multiple of the block sizes. It is advisable to choose block sizes which are factor of sequence length, atleast for the Q block sizes.
27
27
28
28
> In cross attention Image or Video tokens are attending to text tokens sequence length of text tokens is really small and potentially smaller than specified block size so KV block sizes are overwritten to safe values.
29
29
30
-
> KV block sizes must be multiple of 128 since the size of register is 8x128 and in attention KV sequence dim lies on 128 for the multiplications as K is transposed.
30
+
> KV block sizes must be multiple of 128 since the size of register is 8x128 and in attention KV sequence dim lies on 128 for the multiplications as K is transposed.
0 commit comments