[Bugfix][Attention] Preserve post-load tensors across weight reloads (#48251)
Signed-off-by: aoshen02 <aoshen@inferact.ai>
This commit is contained in:
@@ -1573,6 +1573,8 @@ class FlashInferImpl(AttentionImpl):
|
||||
)
|
||||
|
||||
self.sinks: torch.Tensor | None = None
|
||||
# Keep the source so RL weight updates can refresh the runtime tensor.
|
||||
self._sinks_source = sinks
|
||||
if sinks is not None:
|
||||
if sinks.shape[0] != num_heads:
|
||||
raise ValueError(
|
||||
@@ -1633,8 +1635,15 @@ class FlashInferImpl(AttentionImpl):
|
||||
|
||||
# FlashInfer requires attention sinks to be float32
|
||||
def process_weights_after_loading(self, act_dtype: torch.dtype):
|
||||
if self.sinks is not None and self.sinks.dtype != torch.float32:
|
||||
self.sinks = self.sinks.to(torch.float32)
|
||||
source_sinks = self._sinks_source
|
||||
if source_sinks is None:
|
||||
return
|
||||
if source_sinks.dtype == torch.float32:
|
||||
self.sinks = source_sinks
|
||||
elif self.sinks is None or self.sinks.dtype != torch.float32:
|
||||
self.sinks = source_sinks.to(torch.float32)
|
||||
else:
|
||||
self.sinks.copy_(source_sinks)
|
||||
|
||||
def get_xqa_bmm1_scale(self, layer: torch.nn.Module, q_data_type: torch.dtype):
|
||||
bmm1_scale = self.scale
|
||||
|
||||
Reference in New Issue
Block a user