Repository navigation
[bugfix]: benchmark_weight_loading_comparison.py — iterate safe_open via .keys() - #1378
Merged
SolitaryThinker merged 1 commit intoJul 13, 2026
Conversation
The current safetensors API returns a non-iterable handle from `safe_open(...)`; iterating directly with `for name in f` raises `TypeError: 'builtins.safe_open' object is not iterable` and the benchmark script can never produce numbers. Switch both call sites (lines 45, 57) to `for name in f.keys()` to match the upstream safetensors API. No behavior change beyond the script becoming runnable. Reproduces: torchrun --nproc_per_node=2 fastvideo/models/loader/benchmarks/benchmark_weight_loading_comparison.py --model-path /path/to/Wan2.1-T2V-1.3B-Diffusers/snapshots/<hash>/transformer Pre-fix: TypeError at safe_open iteration. Post-fix (Wan2.1-T2V-1.3B on 2x B200): independent ~1.0s, sync broadcast ~0.9s, async broadcast ~0.9s — script runs to completion.
Contributor
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🤖 CI
🔴 PR merge requirementsWaiting for
This rule is failing.
|
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the benchmark_weight_loading_comparison.py script to use .keys() when iterating over safetensors file handles, ensuring compatibility with newer library versions where the handle is not directly iterable. I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The current
safetensorsAPI does not allow iterating asafe_open(...)handle directly (safe_openis not iterable). The two call sites atfastvideo/models/loader/benchmarks/benchmark_weight_loading_comparison.py:45and:57usefor name in f:, which raises:as soon as the script reads the first safetensors shard.
This means
benchmark_weight_loading_comparison.pycannot run on the currentsafetensorsversions installed by FastVideo's mainpyproject.toml. The benchmark numbers that PR #572 cited could not be reproduced without first patching this in the working tree.Fix
Two-line change:
for name in f:→for name in f.keys(): # noqa: SIM118at both call sites. Matches the upstream safetensors API and the existing pattern infastvideo/models/loader/weight_utils.py.Repro
Pre-fix:
TypeErroratload_independent/load_broadcastiteration.Post-fix (verified locally on 2× B200, Wan2.1-T2V-1.3B):
(Cache-state dependent; alternating runs across cold/warm states are needed to compare branches meaningfully — separate concern.)
Test plan
Wan2.1-T2V-1.3B-Diffusers/transformer; noTypeError; numbers produced.for name in fandfor name in f.keys()would have iterated in safetensors-insertion order on any version that supported the former).Test Results
See "Repro" section above for the post-fix output.
This PR is from one of @SolitaryThinker's AI reviewer/fix agents (Gob). It's a 2-line fix; @SolitaryThinker hasn't personally verified the numbers cited above were produced on an unmodified working tree — please ping @SolitaryThinker if anything looks off.