fix: use OrderedDict for proper LRU cache eviction in fp8_cast_bf16.py#1128
Open
modimihir07 wants to merge 2 commits intodeepseek-ai:mainfrom
Open
fix: use OrderedDict for proper LRU cache eviction in fp8_cast_bf16.py#1128modimihir07 wants to merge 2 commits intodeepseek-ai:mainfrom
modimihir07 wants to merge 2 commits intodeepseek-ai:mainfrom
Conversation
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.
Problem
The
loaded_filescache infp8_cast_bf16.pyuses a plain PythondictwithFIFO eviction (
next(iter(loaded_files))). The comment on line 90 says"keep only the 2 most recently used files", but the implementation is actually
FIFO (first-in-first-out), not LRU (least-recently-used).
When
get_tensor()accesses a cached file (e.g., to fetch ascale_invtensorthat lives in a different shard than its weight), that access does NOT update
the file's position in the eviction order. This means:
Fix
dictwithcollections.OrderedDictmove_to_end()on cache hits inget_tensor()to mark as recently usedmove_to_end()when loading current file in main looppopitem(last=False)for proper LRU evictionif len > 2towhile len > 2to handle edge casesTesting
python -m py_compile inference/fp8_cast_bf16.py— passesOrderedDictis from Python stdlib, no new dependencies