[Bugfix][Models] Register sleep-managed runtime buffers (#53507)

Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
Co-authored-by: aoshen02 <aoshen@inferact.ai>
This commit is contained in:
Ronald
2026-08-29 10:32:24 +08:00
committed by GitHub
co-authored by aoshen02
parent 7fd9cc036e
commit 16d6c376bc
6 changed files with 427 additions and 19 deletions
@@ -68,7 +68,9 @@ class RelPositionalEncoding(nn.Module):
pe_positive = torch.flip(pe_positive, [0]).unsqueeze(0)
pe_negative = pe_negative[1:].unsqueeze(0)
self.pe = torch.cat([pe_positive, pe_negative], dim=1)
self.register_buffer(
"pe", torch.cat([pe_positive, pe_negative], dim=1), persistent=False
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
# Tmax = 2 * max_len - 1