Repository navigation
Fix init_quantized_weights: from_pretrained kwargs leak into dispatch, broken dtype fallback - #2161
Conversation
…tie_weights Two defects on the init_quantized_weights path (also reached via hf_ptq.py --low_memory_mode): 1. patched_from_pretrained forwarded **kwargs verbatim into load_checkpoint_and_dispatch(), so any model-construction kwarg raised TypeError. attn_implementation is the common case: 'load_checkpoint_and_dispatch() got an unexpected keyword argument attn_implementation'. It now goes to cls.from_config(), where it belongs. 2. tie_weights() was never called before quantization. Tied parameters such as lm_head.weight (tie_word_embeddings=true, e.g. Qwen2.5-0.5B) are not present in the checkpoint, so they stayed on meta and dispatch_model() raised 'Cannot copy out of meta tensor; no data!'. accelerate documents tie_weights() as a prerequisite of load_checkpoint_and_dispatch(). Reproduced with Qwen/Qwen2.5-0.5B-Instruct, nvfp4, --low_memory_mode on modelopt 0.43.0; both failures occur before any weight is written. Note: these two fixes let the path run to completion but do not make its output correct - see NVIDIA#2160 for the separate root-cause defect (quantization runs on meta tensors before real weights are loaded). Signed-off-by: spped2000 <[email protected]> Co-authored-by: Claude <[email protected]> Signed-off-by: spped2000 <[email protected]>
There was a problem hiding this comment.
Warning
CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.
Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@modelopt/torch/quantization/plugins/accelerate.py`:
- Around line 225-237: Update the model-construction kwargs handling around
cls.from_config to pop both dtype and torch_dtype from kwargs before
load_checkpoint_and_dispatch receives them, while preserving the existing
precedence and fallback selection. Pass the normalized selected value explicitly
as dtype= when constructing the model, and ensure neither alias remains in
kwargs.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 52088e16-a681-425e-86ca-e488c54f6b0d
📒 Files selected for processing (1)
modelopt/torch/quantization/plugins/accelerate.py
…citly CodeRabbit correctly noted that dtype/torch_dtype were read with kwargs.get() and therefore stayed in kwargs. load_checkpoint_and_dispatch() accepts dtype but NOT torch_dtype, so a caller using the legacy alias hit the same TypeError class this PR fixes for attn_implementation. Both aliases are now popped, precedence (dtype > torch_dtype > config) is unchanged, and the resolved value is passed explicitly to load_checkpoint_and_dispatch() so weight casting behaves exactly as before for callers who passed dtype. Signed-off-by: spped2000 <[email protected]> Co-authored-by: Claude <[email protected]> Signed-off-by: spped2000 <[email protected]>
|
Good catch, fixed and pushed. Confirmed the concern is real: Both aliases are now popped, precedence ( |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
modelopt/torch/quantization/plugins/accelerate.py (1)
236-266: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winUse
config.dtypefor the fallback.When
config.dtypeisNone,config.torch_dtypealso returnsNonebecause it is a deprecated alias. The model is then constructed with the defaultfloat32, andload_checkpoint_and_dispatch()receivesdtype=None. This bypasses the intendedfloat16fallback and can cause low-memory loading failures.Use
getattr(config, "dtype", None) or torch.float16and add a regression test for a config without a dtype.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@modelopt/torch/quantization/plugins/accelerate.py` around lines 236 - 266, Update the torch_dtype fallback in the model construction flow to use config.dtype, defaulting to torch.float16 when it is missing or None; do not use the deprecated config.torch_dtype alias. Ensure the resolved dtype is passed consistently to both cls.from_config and load_checkpoint_and_dispatch, and add a regression test covering a configuration without a dtype.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@modelopt/torch/quantization/plugins/accelerate.py`:
- Around line 236-266: Update the torch_dtype fallback in the model construction
flow to use config.dtype, defaulting to torch.float16 when it is missing or
None; do not use the deprecated config.torch_dtype alias. Ensure the resolved
dtype is passed consistently to both cls.from_config and
load_checkpoint_and_dispatch, and add a regression test covering a configuration
without a dtype.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: e4aab36c-0c2b-49d9-8a1d-2cd43f0eec59
📒 Files selected for processing (1)
modelopt/torch/quantization/plugins/accelerate.py
…regression test getattr(config, "torch_dtype", torch.float16) never reaches its default on transformers >= 5: torch_dtype is a deprecated alias of dtype that RETURNS None when unset rather than being absent, so the attribute exists and getattr hands back None. The model was then built as float32 and dtype=None reached load_checkpoint_and_dispatch, on the code path whose entire purpose is loading under tight memory. Verified on transformers 5.13.1: PretrainedConfig().torch_dtype -> None getattr(cfg, 'torch_dtype', torch.float16) -> None # not float16 Reads config.dtype first, falls back to the alias, then to float16 explicitly. Adds a unit test covering kwarg precedence, kwarg consumption, and the no-dtype-in-config fallback. Signed-off-by: spped2000 <[email protected]> Co-authored-by: Claude <[email protected]> Signed-off-by: spped2000 <[email protected]>
|
Third finding addressed (the out-of-diff one) — and it reproduces, so thank you for catching it. Verified on transformers 5.13.1: >>> PretrainedConfig().torch_dtype
None
>>> getattr(PretrainedConfig(), "torch_dtype", torch.float16)
None # not float16 — the getattr default never firesBecause Now reads Note the PR now carries three distinct fixes. Happy to split the dtype one out if you would rather review them separately. |
There was a problem hiding this comment.
Warning
CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.
Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit/torch/quantization/plugins/test_accelerate.py`:
- Line 94: At module scope in the test module, guard the optional dependency
with pytest.importorskip("transformers"), then move the PretrainedConfig import
into the top-level module imports alongside the other imports. Remove any
deferred or test-local PretrainedConfig import while preserving the existing
test behavior.
- Around line 85-93: Update test_init_quantized_weights_dtype_resolution to
invoke the real patched_from_pretrained loader with checkpoint I/O stubbed,
rather than testing a local resolve() helper. Configure conflicting dtype
sources and a non-None deprecated config.torch_dtype, then assert
init_quantized_weights/from_config receives the selected dtype and
attn_implementation, while load_checkpoint_and_dispatch receives only the
supported dispatch arguments; cover the precedence dtype > torch_dtype >
config.dtype > config.torch_dtype > torch.float16.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 172afdc2-0dc2-4fc0-ac70-80e4040120ad
📒 Files selected for processing (2)
modelopt/torch/quantization/plugins/accelerate.pytests/unit/torch/quantization/plugins/test_accelerate.py
🚧 Files skipped from review as they are similar to previous changes (1)
- modelopt/torch/quantization/plugins/accelerate.py
The previous test asserted against a local mirror of the resolution logic, so it would have passed even if patched_from_pretrained were broken. It now drives the real init_quantized_weights context manager with checkpoint I/O stubbed (mtq.quantize/compress, the accelerate device-map helpers and load_checkpoint_and_dispatch are patched) and asserts what each callee actually receives: - from_config gets the resolved dtype and attn_implementation; - dispatch receives neither torch_dtype nor attn_implementation, which it cannot accept, but does receive the resolved dtype; - tie_weights() is called before quantization; - with no dtype anywhere the float16 fallback fires, including the case where the deprecated config.torch_dtype alias returns None. Verified it fails against the pre-PR implementation and passes with the fix. Also moved the transformers import to module scope behind pytest.importorskip, per review. Signed-off-by: spped2000 <[email protected]> Co-authored-by: Claude <[email protected]> Signed-off-by: spped2000 <[email protected]>
|
Both review points addressed — the first one was a fair hit and I have rewritten the test. The test was testing a copy of the logic, not the code. As written it mirrored the resolution order in a local
I checked it actually protects the code: reverting
(One note on the suggested precedence |
There was a problem hiding this comment.
Warning
CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.
Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit/torch/quantization/plugins/test_accelerate.py`:
- Line 98: Move the accel_plugin import from the test method to module scope,
placing it after the module-level pytest.importorskip("transformers") guard.
Keep the existing test behavior unchanged; only retain a deferred import if an
optional-dependency constraint requires it, and document that reason briefly.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 4c7fe034-d661-4717-b8eb-1ba87daae621
📒 Files selected for processing (1)
tests/unit/torch/quantization/plugins/test_accelerate.py
Per the repo's coding guidelines, imports belong at the top of test files. The plugin import now sits after the module-level accelerate/transformers guards. Signed-off-by: spped2000 <[email protected]> Co-authored-by: Claude <[email protected]> Signed-off-by: spped2000 <[email protected]>
|
Done — That is all five review points from this round addressed. Summary of where the PR stands: three independent fixes on the |
|
Thanks for the contribution! This PR now has merge conflicts with We've added the |
…eights Resolve conflicts with NVIDIA#2951 in accelerate.py and NVIDIA#2665 in test_accelerate.py. NVIDIA#2951 added the same model.tie_weights() call after from_config(): keep upstream's call and comment, drop this branch's duplicate. In test_accelerate.py keep both NVIDIA#2665's buffer-offload test and this branch's kwargs/dtype routing test. Signed-off-by: spped2000 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the mock-based unit test with two cases in test_real_quantize_linear, which loads a tiny llama through init_quantized_weights: torch_dtype plus attn_implementation (TypeError on main) and a config without a dtype (float32 instead of float16 on main). Signed-off-by: spped2000 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Pass the resolved dtype to from_config() only. load_checkpoint_and_dispatch() gets a dtype only when the caller supplied one (dtype, or torch_dtype mapped to dtype), so a load without one dispatches exactly as on main. Resolve the dtype from config.dtype with an explicit float16 fallback (config.torch_dtype is only an alias of it) and trim the comments; the root-cause notes live in the PR description. Signed-off-by: spped2000 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks @kevalmorabia97, merged the latest #2951 landed the same New head: |
shengliangxu
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
LGTM: the fix is small and correct. It stops attn_implementation and torch_dtype from reaching load_checkpoint_and_dispatch(), makes the float16 fallback actually apply, and adds GPU regression cases on the real load path.
Needs action:
- Sign off as a human on the edit to the existing
test_real_quantize_linearintests/gpu/torch/quantization/test_real_quantize_cuda.py. The edit is justified: the original case stays as theconfig_dtypeparam with its assertions unchanged, and the two new params only add dtype and attn checks.
No action needed:
- The repo pins
transformers>=5.5, soconfig.dtypealways exists. Dropping theconfig.torch_dtyperead doesn't break older versions. - The caller's dtype is still forwarded to dispatch as
dtype=, the same waymainalready did, so dispatch behaves as before. - No licensing changes, and the PR is well under the size budget.
There was a problem hiding this comment.
Mostly correct; one remaining gap to fix. I reproduced the getattr(config, "torch_dtype", ...) returning None bug, and the new dtype > torch_dtype > config.dtype > float16 chain fixes it. The GPU test covers both fixes.
Needs action:
- Stop other
from_pretrainedkwargs from reachingload_checkpoint_and_dispatch()(inline onaccelerate.py); only two are handled today.
No action needed:
- Keep accepting the legacy
torch_dtypehere:init_quantized_weightsis public andtransformers>=5.5still accepts it with a deprecation warning. Readingconfig.torch_dtypeelsewhere inmodelopt/is tracked in a separate follow-up PR. - Not on a setup-owned path, no licensing change, no changelog entry needed for this fix.
…l takes Split the kwargs by what each call takes instead of listing the ones dispatch can't take. load_checkpoint_and_dispatch() gets only the kwargs in its signature. Without a config= kwarg, AutoConfig.from_pretrained(return_unused_kwargs=True) takes the Hub options (revision, token, local_files_only, ...) and any config attributes, as from_pretrained() does; from_config() gets the rest and raises on any the model does not take. subfolder is joined into the checkpoint path, as load_pretrained() does, so the config and the weights are read from the same place. A non-None device_map or quantization_config is refused up front, since this loader computes the device map and quantizes with quant_cfg. Add hub_kwargs (local_files_only=True, which load_pretrained() forwards) and subfolder cases to test_real_quantize_linear, and pass attn_implementation with the config= of config_without_dtype so a kwarg reaches from_config(). Signed-off-by: spped2000 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Re the bot's checklist item: I reviewed the edit to the existing |
kevalmorabia97
left a comment
There was a problem hiding this comment.
Approving: the kwargs routing is now correct and tested, and it closes the one ask from my earlier review.
No action needed.
No action needed:
- ✔️ Resolved since the last review: other
from_pretrainedkwargs no longer reachload_checkpoint_and_dispatch();quantization_configanddevice_mapnow fail with a clear error. dtype="auto"still fails with anAttributeError; not introduced here, fine as a follow-up.
|
/ok to test ef0dcc4 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2161 +/- ##
==========================================
- Coverage 79.94% 78.54% -1.40%
==========================================
Files 661 661
Lines 75417 77921 +2504
==========================================
+ Hits 60291 61203 +912
- Misses 15126 16718 +1592
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…3049) ### What does this PR do? Type of change: Bug fix `config.torch_dtype` is a deprecated alias of `config.dtype` (transformers>=5.5) that returns `None` when unset instead of raising, so a `getattr(config, "torch_dtype", default)` never reaches its default. This reads `config.dtype` directly in: - `modelopt/torch/export/plugins/hf_spec_export.py`: the DFlash export wrote the string `"None"` as `torch_dtype` for a base config without a dtype; it now falls back to `bfloat16`. - `modelopt/torch/export/unified_export_hf.py`: `_resolve_export_dtype` now reads `config.dtype` (behavior unchanged, no deprecation warning). - `modelopt/torch/opt/plugins/transformers.py`: dropped the redundant `torch_dtype` fallback. Left unchanged: the `"torch_dtype"` keys written to exported `config.json` files and the eagle/spec-dec default configs (on-disk format), and the legacy `torch_dtype=` kwarg accepted by `init_quantized_weights` (public API; handled in #2161). Related: #2161 (same defect in `init_quantized_weights`). ### Usage N/A, no API change. ### Testing - `tests/unit/torch/export/test_hf_spec_rope_export.py` and `test_unified_export_hf.py`: 69 passed (CPU). The new `test_dflash_torch_dtype_inherits_base_or_defaults` uses a real `LlamaConfig` and fails without the fix for the unset-dtype case. - `tests/unit/torch/opt` transformers tests fail at collection with and without this change in my environment (`TypeError` on `None`), so the trainer change is covered only by inspection. ### Before your PR is "*Ready for review*" - Is this change backward compatible?: ✅ - Did you write any new necessary tests?: ✅ - Did you update Changelog?: N/A (internal fix) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Exported models now use the configured data type when available, with a bfloat16 fallback when the configuration does not specify one. * Data type selection and mismatch warnings now reflect the model’s configured data type. * Export behavior is more consistent when configurations provide a data type through the current configuration field, including when the value is missing or `None`. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Keval Morabia <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
LGTM: every earlier concern is fixed, and the kwargs routing and dtype fallback are correct with real-path GPU tests. A human still has to sign off on the edit to an existing test.
Needs action:
- Sign off on the edit to the existing
test_real_quantize_linearintests/gpu/torch/quantization/test_real_quantize_cuda.py. The edit is justified: the original load stays as theconfig_dtypecase with its tie andQTensorWrapperchecks unchanged and one dtype check added. The four new params only change the load kwargs and the expected dtype or attention implementation. kevalmorabia97's approval may already cover this.
No action needed:
- ✔️ Resolved since the last review:
torch_dtypeleaking into dispatch, theconfig.dtypefallback, the mirrored-logic unit test (replaced by real-path cases), and routing every otherfrom_pretrainedkwarg by the callee's signature. - Nothing that loaded on
mainfails now. Kwargs in dispatch's signature still reach it, and every other kwarg already raised aTypeErrorat dispatch. - About 35 added logic lines. No licensing change and no CHANGELOG entry needed.
There was a problem hiding this comment.
Pensieve lgtm review using kmorabia's profile (revision 4).
LGTM: kwargs are now routed by what each callee accepts and the float16 dtype fallback is fixed, but a human must sign off on the edit to an existing test.
Needs action:
- Sign off on the edit to
test_real_quantize_linearintests/gpu/torch/quantization/test_real_quantize_cuda.py. It looks justified: the original load stays as theconfig_dtypecase with its tie andQTensorWrapperassertions unchanged, and one dtype check is added. The four new params only vary the load kwargs and the expected dtype or attention implementation.
No action needed:
- ✔️ Resolved since the last review: other
from_pretrainedkwargs reachingload_checkpoint_and_dispatch()(now filtered viainspect.signature),torch_dtypeleaking into dispatch, and theconfig.dtypefallback. See the earlier review comments in the history. trust_remote_codestill reaches only the config load, so a remote-code model class can still fail infrom_config(). This predates the PR and the author offered a follow-up; I am not blocking on it.dtype="auto"still fails with anAttributeError. It predates this PR and is fine as a follow-up.- About 35 added core lines. No licensing, setup-owned path or changelog concerns.
- Limitation: I could not run tests or check transformers and accelerate behavior here. The new GPU cases and the author's reported mutation checks (reverting each fix fails its own case) were reviewed from the diff and description only. The history was checked for duplicates and no new inline finding repeats it.
Review run: 5c97326f0fae44c5a4b7958f75833768
What does this PR do?
Type of change: Bug fix
Two defects in
init_quantized_weights(public API, and the loader behindhf_ptq.py --low_memory_mode):from_pretrainedkwargs reachload_checkpoint_and_dispatch().patched_from_pretrainedforwarded every kwarg exceptconfigandtrust_remote_codetoload_checkpoint_and_dispatch(), which takes only its own loading options (dtype,max_memory,offload_*, ...), so any other kwarg raised aTypeError. On currentmain,hf_ptq.py --low_memory_mode --attn_implementation sdpafails with:The kwargs are now split by what each call takes:
load_checkpoint_and_dispatch()gets only the kwargs in its signature. A caller'sdtype/torch_dtypereaches it asdtype=, asmainalready did fordtype; without one, dispatch keeps casting each tensor to the dtype the model was built with.config=,AutoConfig.from_pretrained(..., return_unused_kwargs=True)takes the Hub options (revision,token,local_files_only, ...) and config attributes such asuse_cache=False, asfrom_pretrained()does. The weights are still read from the local directory passed (load_pretrained()resolves a Hub ID to one first; a Hub ID passed directly fails in accelerate, onmaintoo).subfolderis joined into the checkpoint path, asload_pretrained()does, so the config and the weights are read from the same place.from_config()gets the rest (e.g.attn_implementationwhenconfig=is passed) and raises on any the model doesn't take. Withconfig=there is no config load, so Hub options also end up here and raise; they raised at dispatch before.Nonedevice_maporquantization_configraises aValueErrorup front, since this loader computes the device map and quantizes withquant_cfg.device_mapis in dispatch's own signature, so the split alone would collide with the computed map. WithNone, both now load wheremainraised.The float16 dtype fallback never fires.
config.torch_dtypeis a deprecated alias ofconfig.dtypethat returnsNonewhen unset instead of being absent, so for a config without a dtypegetattr(config, "torch_dtype", torch.float16)returnsNoneand the model is built and loaded in float32. The dtype now resolves asdtype>torch_dtype>config.dtype>float16(the existing default).This PR originally also added
model.tie_weights(); #2951 landed the same fix, so it was dropped when mergingmain.Usage
No API change.
Testing
test_real_quantize_linear(tests/gpu) gains four load cases on the real path:torch_dtype=torch.float16, attn_implementation="eager";config=without a dtype, withattn_implementation="eager", which then reachesfrom_config();local_files_only=True, a Hub option thatload_pretrained()forwards;subfolder="tiny_llama", loaded from the parent directory.Against
main'saccelerate.py, the first three fail withTypeError: load_checkpoint_and_dispatch() got an unexpected keyword argument ..., and the fourth withValueError: Unrecognized model in ..., because the config is looked up in the parent directory. With this PR all 10 parametrizations (5 load cases × tied/untied) pass. This replaces the mock-based unit test from an earlier revision of this PR, per the test-design guidance in CONTRIBUTING.Reverting each fix alone fails exactly its own cases (checked on CPU):
model_kwargs,config_without_dtypeandhub_kwargs;from_config()(that call reverted tofrom_config(config, dtype=dtype)):config_without_dtype(assert 'sdpa' == 'eager');subfolder;config_without_dtype(assert torch.float32 == torch.float16).Checked by hand on CPU (transformers 5.5.4 and 5.18.0), not in the test:
Nonedevice_maporquantization_configraises theValueErrorabove, and withNoneboth load;TypeErrorfromfrom_config()before quantization;use_cache=Falsereaches the config;revisionandtokenare accepted, as no-ops for a local directory, as infrom_pretrained();experts_implementationandoffload_buffersload;torch_dtype=torch.bfloat16with aconfig=that has no dtype builds the model in bfloat16; without thetorch_dtype→dtypemapping the float16 fallback would win.End-to-end, loading the way
hf_ptq.py --low_memory_modedoes (init_quantized_weights(NVFP4_DEFAULT_CFG)+load_pretrained(..., attn_implementation="sdpa")): a tiny tied llama and a local copy ofQwen/Qwen2.5-0.5B-Instructraise theTypeErrorabove onmain. With this PR they load, also withlocal_files_only=Truepassed throughload_pretrained(). No parameters are left on meta, andlm_headstays tied.Environment: GB10 (SM121, aarch64) in
nvcr.io/nvidia/vllm:26.05.post1-py3(torch 2.12.0a0, transformers 5.6.0, accelerate 1.15.0).test_real_quantize_linearalso passes on CPU with torch 2.14.1 and transformers 5.5.4 and 5.18.0.Not run: the full
hf_ptq.py --low_memory_modecalibrate-and-export flow.Before your PR is "Ready for review"
attn_implementation,local_files_only,revision,tokenanduse_cache=False, which raised aTypeErrorat dispatch, now load, and an unknown kwarg now raises infrom_config()before quantization)CONTRIBUTING.md: N/AAdditional Information
With #2951 and this PR,
hf_ptq.py --low_memory_modeloads with--attn_implementation.Disclosure: prepared with assistance from Claude (Anthropic); everything listed under Testing was run on the hardware stated there.
🤖 Generated with Claude Code