-
Notifications
You must be signed in to change notification settings - Fork 170
[Bug fix] remove max_memory from from_config init in hf_ptq #373
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
Conversation
Signed-off-by: realAsma <[email protected]>
WalkthroughThe get_model function in examples/llm_ptq/example_utils.py now always removes max_memory from model_kwargs2 before constructing the model from a config in the non-VILA path, instead of doing so only for DeciLMForCausalLM architectures. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Utils as example_utils.get_model
participant Cfg as AutoConfig
participant Model as AutoModelForCausalLM
rect rgb(240,248,255)
note over Utils: New flow (non-VILA)
Caller->>Utils: get_model(...)
Utils->>Utils: pop max_memory from model_kwargs2
Utils->>Cfg: from_pretrained(...) / build config
Utils->>Model: from_config(cfg, **model_kwargs2)
Model-->>Caller: model
end
sequenceDiagram
autonumber
actor Caller
participant Utils as example_utils.get_model
participant Cfg as AutoConfig
participant Model as AutoModelForCausalLM
rect rgb(255,250,240)
note over Utils: Previous flow (non-VILA)
Caller->>Utils: get_model(...)
alt arch is DeciLMForCausalLM
Utils->>Utils: pop max_memory from model_kwargs2
else other arch
Utils->>Utils: keep max_memory in model_kwargs2
end
Utils->>Cfg: from_pretrained(...) / build config
Utils->>Model: from_config(cfg, **model_kwargs2)
Model-->>Caller: model
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
# DeciLMForCausalLM does not support max_memory argument | ||
if "architectures" in hf_config and "DeciLMForCausalLM" in hf_config.architectures: | ||
model_kwargs2.pop("max_memory", None) | ||
model_kwargs2.pop("max_memory", None) |
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.
do you actually want to remove line 166-171 as well?
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.
yeah sure I also thought of it. But I do not know why we added the use_seq_device_map
in the first place. So should I remove the entire --use_seq_device_map
?
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.
I recalled that --use_seq_device_map
was added by @sugunav14 for nemotron models that do not distribute evenly on GPUs when initializing with auto device_map.
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.
@cjluo-nv What should we do here? The current fix works. If you are okay with the current fix, can you please approve it?
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.
max_memory is set at line 170. If we don't use it here, we probably don't need line 170. @sugunav14 could you chime in?
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.
yeah, seems like with this change max_memory is never used.
- If we get rid of --use_seq_device_map I think the Llama-Nemotron Ultra will throw an OOM during export
- If we only get rid of max memory I believe we will still hit OOM if we use --use_seq_device_map cause the model will load consuming the full GPU memory
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.
@cjluo-nv @sugunav14 removing max_memory
as in this PR will not cause an OOM. max_memory
is removed when loading with AutoModelForCausalLM.from_config
under init_empy_weights
context. Looks like the fix in this PR is sufficient. Can you please approve this?
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.
@sugunav14 The model initialized here uses AutoModel.from_config(). AutoModel.from_config no longer accepts extra kwargs such as max_memory
(I tested with Llama3 and Qwen3).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #373 +/- ##
=======================================
Coverage 73.46% 73.46%
=======================================
Files 172 172
Lines 17640 17640
=======================================
Hits 12959 12959
Misses 4681 4681 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
# DeciLMForCausalLM does not support max_memory argument | ||
if "architectures" in hf_config and "DeciLMForCausalLM" in hf_config.architectures: | ||
model_kwargs2.pop("max_memory", None) | ||
model_kwargs2.pop("max_memory", None) |
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.
How about we inspect model's signature and keep kwargs if they are supported to avoid such issues in the future?
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.
Discussed with @sugunav14 offline we still need the lines above
Signed-off-by: realAsma <[email protected]>
What does this PR do?
Type of change: ? Bug fix
Overview: ?
Usage
NA
Testing
docker: nvcr.io/nvidia/tensorrt-llm/release:1.1.0rc2.post2
I can run the following:
Summary by CodeRabbit