feat: add automatic device detection for non-CUDA backends#559
Open
curnane-lab wants to merge 1 commit into
Open
feat: add automatic device detection for non-CUDA backends#559curnane-lab wants to merge 1 commit into
curnane-lab wants to merge 1 commit into
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
- Add get_device_type() to auto-detect npu/cuda/cpu via runtime check - Add get_local_device() to return torch.device for current LOCAL_RANK - Replace hardcoded .cuda() and device='cuda' in train_dflash.py with dynamic device selection - Use .to(device, non_blocking=True) for tensor movement to support both CUDA and Ascend NPU without code changes - Maintain backward compatibility: CUDA remains default when available
df9c492 to
2b9f350
Compare
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.
Motivation
The DFlash training script (
scripts/train_dflash.py) currently hardcodes"cuda"as the device type, making it impossible to run on Ascend NPU or CPU without manual code changes. This PR adds automatic device detection so that SpecForge can run on CUDA, Ascend NPU, or CPU out of the box, improving portability for users on non-NVIDIA hardware.Modifications
specforge/utils.py:get_device_type(): auto-detects device viaSPECFORGE_DEVICEenv →torch.cuda→torch.npu→cpuget_local_device(): returnstorch.devicebound toLOCAL_RANKscripts/train_dflash.py:.cuda()/device="cuda"with dynamicget_device_type()/get_local_device().to(device, non_blocking=True)for tensor movement to support both CUDA and NPURelated Issues
N/A (new feature)
Accuracy Test
Benchmark & Profiling
Checklist