fix(models): pin Transformers device_map to GPU 0 when auto sharding breaks sampling#44
Open
Aafiya-H wants to merge 3 commits into
Open
fix(models): pin Transformers device_map to GPU 0 when auto sharding breaks sampling#44Aafiya-H wants to merge 3 commits into
Aafiya-H wants to merge 3 commits into
Conversation
…breaks sampling, fix(examples): close math agent before unload
device_map=auto on multi-GPU nodes produced invalid logits and CUDA multinomial
asserts. Probe logits after load and pin to {: 0} before sampling; retry once on
assert with a restart hint if the context is poisoned. Refactor model reload paths
and harden calculator_agent cleanup in finally.
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
TransformersEngineloads withdevice_map="auto"on multi-GPU hosts (e.g. vision1 with 4× A40). Accelerate can shard small models across GPUs and produce invalid logits, which triggerstorch.multinomialto fail with a device-side assert.device_map={"": 0}) before any sampled generation, since the GPU context cannot be recovered in-process after an assert._assemble_model_kwargs,_load_model_weights,_drop_model_weights) to support pin-and-reload without reloading the tokenizer.unload()so CUDA cache cleanup does not crash after prior CUDA errors.examples/basic/calculator_agent.pycloses the agent in afinallyblock beforemodel.unload()so demo/interactive runs exit cleanly on generation failure.Root cause
On multi-GPU nodes,
device_map="auto"produced collapsed/NaN logits (e.g. max ~1.6 instead of ~26). Forward passes looked fine in some cases, but sampled generation failed with:probability tensor contains either inf, nan or element < 0Pinning the full model to GPU 0 restored healthy logits and generation.
Test plan
python examples/basic/calculator_agent.py— 5/5 tests pass on vision1 (multi-GPU, noCUDA_VISIBLE_DEVICES).to("cuda")/device_map={"": 0}works;device_map="auto"alone fails on this hostdevice_map="auto"is unchanged when logits probe passes