zziang commited on
Commit
c6333a5
·
verified ·
1 Parent(s): c2264fc

export: put dummy tensors on the model device

Browse files
Files changed (1) hide show
  1. kaggle/export_browser.py +10 -7
kaggle/export_browser.py CHANGED
@@ -89,17 +89,18 @@ def stage_lm(mm, torch) -> dict:
89
  return (out.hidden_states[-1], *flat)
90
 
91
  wrapper = Wrapper().float().eval()
 
92
  B, S, P = 1, 4, 6
93
  H = cfg.hidden_size
94
- embeds = torch.randn(B, S, H)
95
- mask = torch.zeros(B, 1, S, P + S)
96
  for i in range(S):
97
  mask[:, :, i, :P + i + 1] = 1.0
98
- pos = torch.arange(P, P + S).unsqueeze(0)
99
  past = []
100
  for _ in range(n):
101
- past.append(torch.randn(B, kv_heads, P, head_dim))
102
- past.append(torch.randn(B, kv_heads, P, head_dim))
103
 
104
  with torch.no_grad():
105
  ref = wrapper(embeds, mask, pos, *past)
@@ -141,7 +142,8 @@ def stage_agg(mm, torch) -> dict:
141
 
142
  lin = mm.linear_proj_audio
143
  dim_in = mm.latent_dim
144
- dummy = torch.randn(1, 1, dim_in)
 
145
  with torch.no_grad():
146
  ref = lin(dummy)
147
  path = OUT / "aggregator.onnx"
@@ -174,7 +176,8 @@ def stage_voc(mm, torch) -> dict:
174
 
175
  voc = Voc().float().eval()
176
  T = 8
177
- dummy = torch.randn(1, T, mm.latent_dim)
 
178
  with torch.no_grad():
179
  ref = voc(dummy)
180
  log(f"voc ref shape {tuple(ref.shape)}")
 
89
  return (out.hidden_states[-1], *flat)
90
 
91
  wrapper = Wrapper().float().eval()
92
+ dev = next(lm.parameters()).device
93
  B, S, P = 1, 4, 6
94
  H = cfg.hidden_size
95
+ embeds = torch.randn(B, S, H, device=dev)
96
+ mask = torch.zeros(B, 1, S, P + S, device=dev)
97
  for i in range(S):
98
  mask[:, :, i, :P + i + 1] = 1.0
99
+ pos = torch.arange(P, P + S, device=dev).unsqueeze(0)
100
  past = []
101
  for _ in range(n):
102
+ past.append(torch.randn(B, kv_heads, P, head_dim, device=dev))
103
+ past.append(torch.randn(B, kv_heads, P, head_dim, device=dev))
104
 
105
  with torch.no_grad():
106
  ref = wrapper(embeds, mask, pos, *past)
 
142
 
143
  lin = mm.linear_proj_audio
144
  dim_in = mm.latent_dim
145
+ dev = next(lin.parameters()).device
146
+ dummy = torch.randn(1, 1, dim_in, device=dev)
147
  with torch.no_grad():
148
  ref = lin(dummy)
149
  path = OUT / "aggregator.onnx"
 
176
 
177
  voc = Voc().float().eval()
178
  T = 8
179
+ dev = next(audio.parameters()).device
180
+ dummy = torch.randn(1, T, mm.latent_dim, device=dev)
181
  with torch.no_grad():
182
  ref = voc(dummy)
183
  log(f"voc ref shape {tuple(ref.shape)}")