Fix ZeroFlow sparse RNG to follow parameter device - #16
Open
kabishou11 wants to merge 1 commit into
Open
kabishou11 wants to merge 1 commit into
kabishou11 wants to merge 1 commit into
Conversation
Construct sparse_grad_rng from the model parameter device instead of hardcoding cuda-if-available, so CPU/MPS models do not pair CUDA generators with non-CUDA tensors during sparse masking. Also drop the duplicate SimpleNamespace import and the redundant SAM get_grad_reduce call already performed by InftyBaseOptimizer. Fixes THUDM#8
This branch has not been deployed
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.
Summary
Fixes #8.
ZeroFlow previously built
sparse_grad_rngwithcuda if torch.cuda.is_available() else cpu, ignoring the actual parameter device. On CPU/MPS models that still see CUDA available, sparse masking can then pair a CUDA generator with non-CUDA tensors.This change:
next(model.parameters()).device(cpu for non-cuda devices, sincetorch.Generatoronly supports cpu/cuda)SimpleNamespaceimportget_grad_reducecall inSAM(already done inInftyBaseOptimizer.__init__)Test plan
uv run --with pytest pytest -q tests/optim/test_zeroth_order_updates.py— 3 passed