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
For any PATTERN not in {0...5}, we introduced the simple abstract concept of **Patch Functor**. Users can implement a subclass of Patch Functor to convert an unknown Pattern into a known PATTERN, and for some models, users may also need to fuse the operations within the blocks for loop into block forward.
@@ -341,6 +358,50 @@ cache_dit.enable_cache(
341
358
)
342
359
```
343
360
361
+
### 📚How to use ParamsModifier
362
+
363
+
Sometimes you may encounter more complex cases, such as **Wan 2.2 MoE**, which has more than one Transformer (namely `transformer` and `transformer_2`), or FLUX.1, which has multiple transformer blocks (namely `single_transformer_blocks` and `transformer_blocks`). cache-dit will assign separate cache contexts for different `blocks` instances but share the same `cache_config` by default. Users who want to achieve fine-grained control over different cache contexts can consider using `ParamsModifier`. Just pass the `ParamsModifier` per `blocks` to the `BlockAdapter` or `enable_cache(...)` API. Then, the shared `cache_config` will be overwritten by the new configurations from the `ParamsModifier`. For example:
364
+
365
+
```python
366
+
from cache_dit import ParamsModifier
367
+
368
+
cache_dit.enable_cache(
369
+
BlockAdapter(
370
+
pipe=pipe, # FLUX.1, etc.
371
+
transformer=pipe.transformer,
372
+
blocks=[
373
+
pipe.transformer.transformer_blocks,
374
+
pipe.transformer.single_transformer_blocks,
375
+
],
376
+
forward_pattern=[
377
+
ForwardPattern.Pattern_1,
378
+
ForwardPattern.Pattern_3,
379
+
],
380
+
),
381
+
# Basic shared cache config
382
+
cache_config=DBCacheConfig(...),
383
+
params_modifiers=[
384
+
ParamsModifier(
385
+
# Modified config only for transformer_blocks
386
+
# Must call the `reset` method of DBCacheConfig.
387
+
cache_config=DBCacheConfig().reset(
388
+
Fn_compute_blocks=8,
389
+
residual_diff_threshold=0.08,
390
+
),
391
+
),
392
+
ParamsModifier(
393
+
# Modified config only for single_transformer_blocks
394
+
#NOTE: FLUX.1, single_transformer_blocks should have `higher`
395
+
# residual_diff_threshold because of the precision error
@@ -743,9 +804,8 @@ This function seamlessly integrates with both standard diffusion pipelines and c
743
804
Whether to use separate cfg ornot, such asin Wan 2.1, Qwen-Image. For models that fuse CFGand non-CFG into a single forward step, set enable_separate_cfg asFalse. Examples include: CogVideoX, HunyuanVideo, Mochi, etc.
744
805
-`cfg_compute_first`: (`bool`, *required*, defaults to False):
745
806
Whether to compute cfg forward first, default isFalse, meaning:
746
-
0, 2, 4, ...-> non-CFG step;
747
-
1, 3, 5, ...->CFG step.
748
-
-`cfg_diff_compute_separate`: (`bool`, *required*, defaults to True):
-`cfg_diff_compute_separate`: (`bool`, *required*, defaults to True):
749
809
Whether to compute separate difference values forCFGand non-CFG steps, default isTrue. If False, we will use the computed difference from the current non-CFG transformer step for the current CFG step.
750
810
-`num_inference_steps` (`int`, *optional*, defaults to None):
751
811
num_inference_steps for DiffusionPipeline, used to adjust some internal settings
0 commit comments