Skip to content

Fix train.py: indentation crash, stale package import, console encoding - #49

Open
BladeMasterHi wants to merge 2 commits into
MineDojo:mainfrom
BladeMasterHi:fix/train-script-crash-and-package-shadowing
Open

Fix train.py: indentation crash, stale package import, console encoding#49
BladeMasterHi wants to merge 2 commits into
MineDojo:mainfrom
BladeMasterHi:fix/train-script-crash-and-package-shadowing

Conversation

@BladeMasterHi

Copy link
Copy Markdown

Summary

  • scripts/train.py had an IndentationError at the output = model(batch_dict) line, blocking any run before it started.
  • The sys.path fix at the top of the file ran after the from nitrogen... imports, so it had no effect — a stray pip install -e . elsewhere on the machine could shadow the local nitrogen package with a different copy. Imports are now ordered so the local repo always wins.
  • The final success print used a character that crashes on a cp1252 Windows console, right before torch.save(...) — losing the trained weights. stdout/stderr are now reconfigured to UTF-8.
  • scripts/one_batch_forward.py is a minimal, working smoke test: loads a checkpoint, builds one real batch via GamingDataset/create_collate_fn, and runs model(batch_dict) to validate shapes end-to-end without a full training run.

Test plan

  • python -m py_compile scripts/train.py scripts/one_batch_forward.py
  • python scripts/one_batch_forward.py — forward pass succeeds, prints per-tensor shapes and a loss value
  • python scripts/train.py --epochs 1 --batch-size 2 on a small sample — full loop (forward, backward, optimizer step, checkpoint save) completes with exit code 0

- output = model(batch_dict) had lost its indentation, causing an
  IndentationError before the script could start.
- Reorder sys.path setup before the nitrogen imports so a stray
  editable install elsewhere on the machine cannot shadow the local
  package.
- Reconfigure stdout/stderr to UTF-8 so a non-ASCII character in the
  final print no longer crashes the run right before torch.save().
- Rewrite one_batch_forward.py as a minimal working forward-pass
  smoke test against a real checkpoint and dataset batch.
…rder

- pil_to_tensor only rescaled to [0,1]; the vision encoder
  (AutoImageProcessor for siglip2) expects [-1,1]. Fine-tuning was
  silently teaching the model on a different pixel distribution than
  what scripts/serve.py feeds it at inference time.
- GamingDataset concatenated actions as [j_left, j_right, buttons],
  but NitrogenTokenizer.pack_actions/unpack_actions (old_layout=False)
  expect [buttons, j_left, j_right]. Training didn't crash on this
  (plain MSE target), but scripts/serve.py would have decoded garbage
  j_left/j_right after fine-tuning, breaking scripts/play.py's mouse
  control with no visible error.

Both verified with a real forward+backward+save smoke test against
the checkpoint and dataset (loss stable, exit code 0), plus a live
ZeroMQ round trip through scripts/serve.py (info/reset/predict).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant