-
Notifications
You must be signed in to change notification settings - Fork 280
ignore _update_mamba_mask for AWQ sequential tracing #1925
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
ignore _update_mamba_mask for AWQ sequential tracing #1925
Conversation
|
👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review. Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed. |
Summary of ChangesHello @toncao, 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 resolves a critical "TraceError" that occurs when performing AWQ sequential tracing on models that incorporate Mamba-2 layers. The error stemmed from symbolic tracing variables being used in control flow within the "_update_mamba_mask" function. By explicitly adding this function to the tracing ignore list, the PR ensures that these models can now be successfully traced without encountering the previously reported issues. Highlights
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly addresses a tracing error with Mamba-2 models by adding _update_mamba_mask to the tracing_ignore list. This change is necessary and well-justified. I have one suggestion to improve code maintainability.
brian-dellabetta
left a comment
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.
Thanks @toncao , makes sense to me
SUMMARY: In models with mamba-2 layers e.g., [nvidia/NVIDIA-Nemotron-Nano-12B-v2](https://huggingface.co/nvidia/NVIDIA-Nemotron-Nano-12B-v2), [Qwen/Qwen3-Next-80B-A3B-Instruct](https://huggingface.co/Qwen/Qwen3-Next-80B-A3B-Instruct), tracing _update_mamba_masks would lead to ``` File "NemotronHModel_8045287568680_autowrapped", line 57, in forward File "/mnt/LinuxDrive/huggingface/modules/transformers_modules/NVIDIA_hyphen_Nemotron_hyphen_Nano_hyphen_12B_hyphen_v2/modeling_nemotron_h.py", line 1461, in _update_mamba_mask if cache_position[0] > 0 or (attention_mask is not None and torch.all(attention_mask == 1)): ^^^^^^^^^^^^^^^^^^^^^ File "/home/toncao/anaconda3/envs/llm-compressor_v1/lib/python3.12/site-packages/transformers/utils/fx.py", line 674, in __bool__ return super().__bool__() ^^^^^^^^^^^^^^^^^^ File "/home/toncao/anaconda3/envs/llm-compressor_v1/lib/python3.12/site-packages/torch/fx/proxy.py", line 577, in __bool__ return self.tracer.to_bool(self) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/toncao/anaconda3/envs/llm-compressor_v1/lib/python3.12/site-packages/torch/fx/proxy.py", line 388, in to_bool raise TraceError( torch.fx.proxy.TraceError: symbolically traced variables cannot be used as inputs to control flow ``` from the function: ``` def _update_mamba_mask(self, attention_mask, cache_position): -- """ No need for zeroing states when 1. Cached forward 2. Attending to all inputs """ mamba_mask = attention_mask if cache_position[0] > 0 or (attention_mask is not None and torch.all(attention_mask == 1)): mamba_mask = None return mamba_mask ``` And thus, adding _update_mamba_masks to the ignore tracing list makes AWQ sequential tracing works. TEST PLAN: local make test results: ``` ===================================================== short test summary info ===================================================== FAILED tests/llmcompressor/modeling/test_calib_deepseek_v3.py::test_calib_deepseekv3_module - torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 56.00 MiB. GPU 0 has a total capacity of 23.57 GiB of which 14.1... FAILED tests/llmcompressor/utils/test_helpers.py::test_disable_cache[MllamaForConditionalGeneration-meta-llama/Llama-3.2-11B-Vision-Instruct] - huggingface_hub.errors.GatedRepoError: 403 Client Error. (Request ID: Root=1-68ee275c-378c35b1649b823602164fc0;24ebe331-9031-4... FAILED tests/lmeval/test_lmeval.py::TestLMEval::test_lm_eval[None] - TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'NoneType' ====================================== 3 failed, 242 passed, 4 skipped in 129.47s (0:02:09) ======================================= ``` Co-authored-by: toncao <cpatonn@gmail.com> Co-authored-by: Brian Dellabetta <brian-dellabetta@users.noreply.github.com>
SUMMARY: In models with mamba-2 layers e.g., [nvidia/NVIDIA-Nemotron-Nano-12B-v2](https://huggingface.co/nvidia/NVIDIA-Nemotron-Nano-12B-v2), [Qwen/Qwen3-Next-80B-A3B-Instruct](https://huggingface.co/Qwen/Qwen3-Next-80B-A3B-Instruct), tracing _update_mamba_masks would lead to ``` File "NemotronHModel_8045287568680_autowrapped", line 57, in forward File "/mnt/LinuxDrive/huggingface/modules/transformers_modules/NVIDIA_hyphen_Nemotron_hyphen_Nano_hyphen_12B_hyphen_v2/modeling_nemotron_h.py", line 1461, in _update_mamba_mask if cache_position[0] > 0 or (attention_mask is not None and torch.all(attention_mask == 1)): ^^^^^^^^^^^^^^^^^^^^^ File "/home/toncao/anaconda3/envs/llm-compressor_v1/lib/python3.12/site-packages/transformers/utils/fx.py", line 674, in __bool__ return super().__bool__() ^^^^^^^^^^^^^^^^^^ File "/home/toncao/anaconda3/envs/llm-compressor_v1/lib/python3.12/site-packages/torch/fx/proxy.py", line 577, in __bool__ return self.tracer.to_bool(self) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/toncao/anaconda3/envs/llm-compressor_v1/lib/python3.12/site-packages/torch/fx/proxy.py", line 388, in to_bool raise TraceError( torch.fx.proxy.TraceError: symbolically traced variables cannot be used as inputs to control flow ``` from the function: ``` def _update_mamba_mask(self, attention_mask, cache_position): -- """ No need for zeroing states when 1. Cached forward 2. Attending to all inputs """ mamba_mask = attention_mask if cache_position[0] > 0 or (attention_mask is not None and torch.all(attention_mask == 1)): mamba_mask = None return mamba_mask ``` And thus, adding _update_mamba_masks to the ignore tracing list makes AWQ sequential tracing works. TEST PLAN: local make test results: ``` ===================================================== short test summary info ===================================================== FAILED tests/llmcompressor/modeling/test_calib_deepseek_v3.py::test_calib_deepseekv3_module - torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 56.00 MiB. GPU 0 has a total capacity of 23.57 GiB of which 14.1... FAILED tests/llmcompressor/utils/test_helpers.py::test_disable_cache[MllamaForConditionalGeneration-meta-llama/Llama-3.2-11B-Vision-Instruct] - huggingface_hub.errors.GatedRepoError: 403 Client Error. (Request ID: Root=1-68ee275c-378c35b1649b823602164fc0;24ebe331-9031-4... FAILED tests/lmeval/test_lmeval.py::TestLMEval::test_lm_eval[None] - TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'NoneType' ====================================== 3 failed, 242 passed, 4 skipped in 129.47s (0:02:09) ======================================= ``` Co-authored-by: toncao <cpatonn@gmail.com> Co-authored-by: Brian Dellabetta <brian-dellabetta@users.noreply.github.com> Signed-off-by: LeiZhang <isleizhang@outlook.com>
SUMMARY:
In models with mamba-2 layers e.g., nvidia/NVIDIA-Nemotron-Nano-12B-v2, Qwen/Qwen3-Next-80B-A3B-Instruct, tracing _update_mamba_masks would lead to
from the function:
And thus, adding _update_mamba_masks to the ignore tracing list makes AWQ sequential tracing works.
TEST PLAN:
local make test results: