Fix train.py: indentation crash, stale package import, console encoding - #49
Open
BladeMasterHi wants to merge 2 commits into
Open
Conversation
- 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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scripts/train.pyhad anIndentationErrorat theoutput = model(batch_dict)line, blocking any run before it started.sys.pathfix at the top of the file ran after thefrom nitrogen...imports, so it had no effect — a straypip install -e .elsewhere on the machine could shadow the localnitrogenpackage with a different copy. Imports are now ordered so the local repo always wins.✓character that crashes on acp1252Windows console, right beforetorch.save(...)— losing the trained weights. stdout/stderr are now reconfigured to UTF-8.scripts/one_batch_forward.pyis a minimal, working smoke test: loads a checkpoint, builds one real batch viaGamingDataset/create_collate_fn, and runsmodel(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.pypython scripts/one_batch_forward.py— forward pass succeeds, prints per-tensor shapes and a loss valuepython scripts/train.py --epochs 1 --batch-size 2on a small sample — full loop (forward, backward, optimizer step, checkpoint save) completes with exit code 0