Fix: strip leading [BOS] token before validity-mask check and AST des…#26
Merged
Merged
Conversation
|
@chaudhryumer is attempting to deploy a commit to the chuzaairforce-7557's projects Team on Vercel. A member of the Team first needs to authorize it. |
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
Fixes two related bugs in the neural inference pipeline that caused
inference/solve.py'ssolve()to either produce empty output or faildeserialization on every call, regardless of model training quality.
Bugs found and fixed
1.
inference/beam_search.py— validity mask rejected every candidate tokenis_valid_prefix()'s grammar parses SLaNg AST node types (NODE:TERM,NODE:FRAC,OP:*) starting at index 0. Beam search seeds every beamwith
[bos_id]before decoding starts, and passed the full tokensequence (including
[BOS]) intonode_pool.mask()on every step.Since
[BOS]matches none of the grammar's valid starting tokens, everysingle candidate token was masked as invalid on the very first decoding
step, so
safe_logitswas always all-infand generation terminatedimmediately with only the seed
[BOS]token.Fix: strip the leading
[BOS]token before passing tonode_pool.mask(), since it is a decoder-input framing token, not partof the AST grammar being validated.
2.
inference/solve.py— output deserialization failed on[BOS]Same root issue at a second call site:
solve()passedresult["tokens"](still including the seed[BOS]) directly into_verify_output(), which deserializes the token sequence as a SLaNgAST. This failed immediately with:
Fix: strip the leading
[BOS]fromoutput_token_stringsbeforecalling
_verify_output().Also verified while investigating
inference/solve.py's defaultmodel_path(model/model.pkl) loadsa stale checkpoint with an entirely different architecture (flat
nn.Transformer,fc_out/pos_encoderkeys) than the tree-basedCalculusSolverModelactually trained bytrain.py(
checkpoints/final/best.pt). Loadingmodel/model.pklby defaultcauses
load_state_dict()to fail with dozens of missing/unexpectedkey errors. Not changed in this PR (didn't want to change a public
default without discussion), but worth a follow-up — either update
the default
model_path, or keepmodel/model.pklin sync with thecurrently-trained architecture.
Testing
Verified end-to-end with a trained checkpoint from
train.py:Before this fix:
output_tokens: ['[BOS]'], deserialization error.After this fix: generation proceeds past the first token and no longer
fails on
[BOS]at either the validity-mask or deserialization stage.Known follow-up
Training run so far (
docs/TRAINING_RESULTS.md, 10 epochs,max_steps=500) showsVal Ruleloss plateaued at ~0.51 from epoch 1onward with no further improvement, while
Val SeqandVal Verifydropped close to zero — likely exposure bias (teacher-forced validation
loss vs. free-running beam search generation) combined with only
~14% of the training set being seen per epoch. Currently re-running
with
max_steps=3500(full epoch coverage),learning_rate=0.0003,and
epochs=15to see if the rule-loss plateau breaks. Will follow upwith updated
docs/TRAINING_RESULTS.md/docs/EVAL_RESULTS.mdoncethat run completes.