Skip to content

fix: correct dict comprehension syntax in save_pretrained to prevent ValueError - #47346

Closed
ajayraj30002 wants to merge 1 commit into
huggingface:mainfrom
ajayraj30002:ajayraj30002-patch-1
Closed

fix: correct dict comprehension syntax in save_pretrained to prevent ValueError#47346
ajayraj30002 wants to merge 1 commit into
huggingface:mainfrom
ajayraj30002:ajayraj30002-patch-1

Conversation

@ajayraj30002

Copy link
Copy Markdown

What does this PR do?

Fixes #47333

There is a small syntax error in modeling_utils.py that crashes the save_pretrained process for models with offloaded modules.

Currently, weight_map.update() is being passed a generator yielding single-key dictionaries, which throws a ValueError because update() expects a sequence of 2-item tuples.

Before:
weight_map.update({k: os.path.basename(shard_file)} for k in shard_state_dict.keys())

After (moved the closing brace to make it a standard dict comprehension):
weight_map.update({k: os.path.basename(shard_file) for k in shard_state_dict.keys()})

Code Agent Policy

  • (First-time contributors only): I confirm that this PR description and code is not written by an LLM or code agent

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline and the Pull Request checks?
  • Was this discussed/approved via a Github issue or the forum? Please add a link to it if that's the case.

Who can review?

@Cyrilvallez @SunMarc (Tagging you as you were mentioned in the original issue!)

This PR corrects a syntax typo in weight_map.update that causes a ValueError when offloaded modules are saved.
Fixes #47333
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution 🤗!

CI Security Gate — automatic approval blocked

This PR was not automatically approved for CI because the security gate failed.

Possible reasons:

  • The PR touches 50 or more files — only PRs with fewer than 50 changed files are automatically approved
  • A changed file is outside the allowed directories (src/, tests/, docs/, utils/), has a disallowed extension (only .py, .txt, .md permitted outside tests/ and docs/), or is not .md/.yml inside docs/
  • A new high-severity security issue was detected in the changed Python files (Bandit check)

See the workflow run for the exact violations.

A maintainer can review and manually approve CI if a finding is a false positive.

@Rocketknight1

Copy link
Copy Markdown
Member

#47336 was open already with this fix + the actual fix!

@ajayraj30002
ajayraj30002 deleted the ajayraj30002-patch-1 branch July 16, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Offloading] Cannot save disk-offloaded Qwen/Qwen3-30B-A3B

2 participants