vectominist commited on
Commit
6ca376e
·
verified ·
1 Parent(s): 8710021

fix `self.pe` init issue

Browse files
Files changed (1) hide show
  1. usad_modules.py +7 -0
usad_modules.py CHANGED
@@ -367,6 +367,13 @@ class RelPositionalEncoding(nn.Module):
367
  self.pe = None
368
 
369
  def extend_pe(self, x: torch.Tensor) -> None:
 
 
 
 
 
 
 
370
  if self.pe is not None:
371
  if self.pe.size(1) >= x.size(1) * 2 - 1:
372
  if self.pe.dtype != x.dtype or self.pe.device != x.device:
 
367
  self.pe = None
368
 
369
  def extend_pe(self, x: torch.Tensor) -> None:
370
+ # ``from_pretrained`` can initialize modules on the meta device while it
371
+ # streams checkpoint weights. This runtime cache is not checkpoint
372
+ # state, so a meta tensor cannot be materialized with ``Tensor.to``.
373
+ # Drop it and rebuild it below for the actual input device instead.
374
+ if self.pe is not None and self.pe.is_meta:
375
+ self.pe = None
376
+
377
  if self.pe is not None:
378
  if self.pe.size(1) >= x.size(1) * 2 - 1:
379
  if self.pe.dtype != x.dtype or self.pe.device != x.device: