[diffusion] fix TeaCache silently fails with --enable-teacache#19964
[diffusion] fix TeaCache silently fails with --enable-teacache#19964mickqian merged 7 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug that prevented the TeaCache optimization from activating, even when explicitly enabled. By refining the Req object's attribute handling, the system now correctly delegates TeaCache parameters, leading to significant performance improvements for models utilizing this caching mechanism. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a bug that caused TeaCache to be silently disabled. The issue stemmed from the Req class defining a teacache_params field, which was initialized to None. This prevented the __getattr__ method from delegating the attribute lookup to the sampling_params object where the actual configuration resides. The fix involves removing the teacache_params field from the Req class, which correctly restores the delegation behavior. The corresponding unused imports have also been removed. The change is well-targeted and effectively resolves the bug.
|
/tag-and-rerun-ci |
|
Should I update According to Below is the results from benchmarking "wan2_1_t2v_1.3b_teacache_enabled": {
"stages_ms": {
"DenoisingStage": 4598.36,
"InputValidationStage": 0.07,
"DecodingStage": 552.92,
"LatentPreparationStage": 0.26,
"per_frame_generation": Infinity,
"TextEncodingStage": 1114.01,
"TimestepPreparationStage": 2.1
},
"denoise_step_ms": {
"0": 94.24,
"1": 172.68,
"2": 169.48,
"3": 169.08,
"4": 168.38,
"5": 167.27,
"6": 62.95,
"7": 119.56,
"8": 53.34,
"9": 121.85,
"10": 47.64,
"11": 125.75,
"12": 3.24,
"13": 48.21,
"14": 125.17,
"15": 3.71,
"16": 48.15,
"17": 124.61,
"18": 3.3,
"19": 47.25,
"20": 129.33,
"21": 3.11,
"22": 48.03,
"23": 127.46,
"24": 3.37,
"25": 45.6,
"26": 127.17,
"27": 3.35,
"28": 49.83,
"29": 125.42,
"30": 3.19,
"31": 42.76,
"32": 131.19,
"33": 2.93,
"34": 130.04,
"35": 44.77,
"36": 131.45,
"37": 44.06,
"38": 131.02,
"39": 43.48,
"40": 130.42,
"41": 45.24,
"42": 129.46,
"43": 44.6,
"44": 130.33,
"45": 173.84,
"46": 175.58,
"47": 168.16,
"48": 173.85,
"49": 177.56
},
"expected_e2e_ms": 6497.84,
"expected_avg_denoise_ms": 91.85,
"expected_median_denoise_ms": 120.7
}, |
|
@eitanturok if the performance is theoretically affected by this PR, then yes. Otherwise no. cheers |
|
@mickqian I updated Any other comments? |
|
@mickqian Nvidia CI passed and PR is approved, ready for merge — SGLDHelper bot |
Motivation
This PR fixes a bug where TeaCache was silently disabled even when
--enable-teacachewas specified.The issue stemmed from
Req.teacache_paramsdefaulting toNone, which prevented the attribute lookup from delegating to the actual values stored insampling_params. This is a prerequisite for #19957.The Problem
In
cache/teacache.py, the cache is bypassed ifforward_batch.teacache_paramsisNone.Currently, the
Reqclass andsampling_paramsboth have ateacache_paramsfield.WanT2V_1_3B_SamplingParams) correctly populatesampling_params.teacache_params.Reqobject initializes its ownteacache_paramsasNone.Requses__getattr__for delegation, it only looks atsampling_paramsif the attribute does not exist onReq.Req.teacache_paramsexists (asNone), the delegation never happens, and the cache logic assumes TeaCache is disabled.The Solution
teacache_paramsfield from theReqclass.Reqnow correctly hits__getattr__whenteacache_paramsis accessed.sampling_params.teacache_params, ensuring the model-specific configurations are respected.Verification Results
With teacache enabled,
Wan2.1-T2V-1.3Bgenerates a video 1.7x faster on my branch but is the same speed on master when compared to the baseline generation time. This is run on an A100. Moreover, the video is lower quality on my branch (this is expected as we are skipping steps) but the exact same quality as the baseline on main.Teacache (my branch)
fight-teacache-mybranch.mp4
[03-05 15:15:35] Completed batch processing. Generated 1 outputs in 86.46 seconds
Teacache (main)
[03-05 15:27:20] Completed batch processing. Generated 1 outputs in 150.74 seconds
fight-teacache-main.mp4
Baseline (main)
[03-05 15:48:35] Completed batch processing. Generated 1 outputs in 150.62 seconds
fight-baseline-main.mp4
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci