Skip to content

fix: promote None-initialized kwarg to list in forward_capture#1979

Merged
wenhuach21 merged 1 commit into
intel:mainfrom
ramkrishs:fix/forward-capture-none-kwarg-extend
Jul 2, 2026
Merged

fix: promote None-initialized kwarg to list in forward_capture#1979
wenhuach21 merged 1 commit into
intel:mainfrom
ramkrishs:fix/forward-capture-none-kwarg-extend

Conversation

@ramkrishs

@ramkrishs ramkrishs commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

forward_capture in auto_round/calibration/hooks.py raised an AttributeError
during calibration when an optional kwarg (e.g. a sparse-attention mask in MoE
models) was None on the first calibration sample but a real Tensor on a later
one.

Root cause: The initialization branch stores None directly when a kwarg's
value is None:

if data is None or key in state.model_context.shared_cache_keys:
    state.inputs[name][key] = data   # stores None

On the next sample, the append branch assumed the stored value was always a list
and called .append() or .extend() on it, raising:

AttributeError: 'NoneType' object has no attribute 'extend'

Fix: One guard before the append/extend calls promotes a stored None to an
empty list, covering both batch_size <= 1 (.append) and batch_size > 1
(.extend) paths.

Type of Change

  • Bug fix

Related Issues

Fixes #1950

Testing

Added three regression tests in test/test_cpu/core/test_forward_capture_none_kwarg.py:

Test What it covers
test_none_then_tensor_kwarg_batch_size_1 None → Tensor transition, batch_size=1 (.append path)
test_none_then_tensor_kwarg_batch_size_gt1 None → Tensor transition, batch_size>1 (.extend path)
test_normal_tensor_kwarg_unaffected Kwargs that are always Tensors still accumulate correctly

All three pass locally against the fix.

Checklist Before Submitting

  • My code has been tested locally.
  • Documentation has been updated as needed.
  • New or updated tests are included where applicable.
  • The CUDA CI has passed. You can trigger it by commenting /azp run Unit-Test-CUDA-AutoRound.

When an optional kwarg (e.g. a sparse-attention mask) is absent on the
first calibration sample, the initialization branch stores it as None.
If a later sample delivers a real Tensor for the same key, the append
branch called None.append() / None.extend(), raising:

    AttributeError: 'NoneType' object has no attribute 'extend'

Fix: before calling .append()/.extend(), check whether the stored value
is None and promote it to an empty list first.

Fixes: intel#1950
Signed-off-by: Ram Sathyavageeswaran <ramkrishs@outlook.com>
@ramkrishs

Copy link
Copy Markdown
Contributor Author

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 1979 in repo intel/auto-round

@n1ck-guo n1ck-guo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your effor.

@chensuyue

Copy link
Copy Markdown
Contributor

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@wenhuach21 wenhuach21 added this to the 0.14.0 milestone Jul 2, 2026
@wenhuach21 wenhuach21 merged commit 0622d47 into intel:main Jul 2, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: forward_capture AttributeError ('NoneType' has no attribute 'extend') during MoE calibration when a kwarg is None-then-Tensor

4 participants