You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix empty tensor shape issue in DynamicCache for torch.compile
Fixes#42027
This commit fixes a regression where torch.cat receives incorrectly
shaped empty tensors during model tracing with torch.compile.
The issue was introduced in commit dc11a3c where empty cache tensors
were initialized as 1D tensors with shape [0] using torch.tensor([]).
When these are concatenated with 4D key/value tensors [batch, heads, seq, dim]
along dim=-2, torch.compile's tracing fails.
Changes:
- Modified DynamicLayer.lazy_initialization() to create properly shaped
4D empty tensors [batch, heads, 0, dim] instead of 1D [0]
- Modified QuantizedLayer.update() to reset cache with proper 4D shape
- Used torch.zeros() with explicit shape matching key_states dimensions
This ensures torch.cat operations work correctly in both eager and
compiled modes.
0 commit comments