summaryrefslogtreecommitdiff
path: root/src/model_api.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/model_api.py')
-rw-r--r--src/model_api.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/model_api.py b/src/model_api.py
index 31ffe31..85b5d55 100644
--- a/src/model_api.py
+++ b/src/model_api.py
@@ -32,10 +32,16 @@ def greedy_decode(model: PrimeModel, x: torch.Tensor, cfg: Config, max_len: int
Inputs are LEFT-padded to the global layout so positions match training exactly
(batch/singleton invariance — codex BLOCKER fix)."""
+ try:
+ device = next(model.parameters()).device
+ except StopIteration:
+ device = x.device
+ if x.device != device:
+ x = x.to(device)
x = pad_inputs(x, cfg)
max_len = max_len or cfg.max_out_len
B = x.shape[0]
- y_in = torch.full((B, 1), cfg.eos_id, dtype=torch.long, device=x.device)
+ y_in = torch.full((B, 1), cfg.eos_id, dtype=torch.long, device=device)
for _ in range(max_len):
out = model(x, y_in)
nxt = out["logits"][:, -1].argmax(-1)