[WIP] Fix NotImplementedError during model.to(device) #402
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.
Fix NotImplementedError with AffineQuantizedTensor on CUDA
Problem
After model quantization with torchao, moving the model to CUDA fails with NotImplementedError because direct
.to(device)calls don't work with AffineQuantizedTensor on some torch versions.Root Cause
The code uses direct
.to(device)calls to move the model BEFORE quantization, but aftertorch.compile()andquantize_(), there's no explicit device movement using the safe_recursive_to_device()method that handles AffineQuantizedTensor properly.Plan
.to()calls don't work with AffineQuantizedTensor.to(device)calls with_recursive_to_device()for model initializationOriginal prompt
This section details on the original issue you should resolve
<issue_title>BUG - commit #17825ee(?) (NotImplementedError related to AffineQuantizedTensor when attempting to move the quantized model to CUDA)</issue_title>
<issue_description>Describe the bug
After updating to the latest commit (7aa2737 - "Revert 'fix: implement platform-specific audio playback reset logic'"), music generation fails with a NotImplementedError related to AffineQuantizedTensor when attempting to move the quantized model to CUDA. The error occurs in torchao's quantization layer during the model.to(device) operation, specifically with the aten._has_compatible_shallow_copy_type operator not being implemented for AffineQuantizedTensor types.
Can confirm reverting to c3dcf14 resolves this issue. VERY sure the issue is introduced somewhere in 17825ee
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Music generation should proceed normally as it did before the update. The model should successfully move to CUDA device and generate audio output.
Desktop (please complete the following information):
Additional context
The issue appears to have been introduced in commit #17825ee ("Merge mainline commits as of 2026/02/08 05:16 UTC with MPS optimizations and do optimization checks"). The installation was fully functional approximately 8 hours ago before pulling the latest updates. The error specifically occurs when torchao's AffineQuantizedTensor (used for model quantization) attempts to be moved to CUDA, suggesting a compatibility issue between the quantization implementation and PyTorch's device transfer mechanisms.