Skip to content

Fix vocab kwarg collision in eval_testdata's PertBatchCollator call - #53

Merged
davidliwei merged 2 commits into
mainfrom
fix/eval-testdata-vocab-collision
Sep 2, 2026
Merged

Fix vocab kwarg collision in eval_testdata's PertBatchCollator call#53
davidliwei merged 2 commits into
mainfrom
fix/eval-testdata-vocab-collision

Conversation

@davidliwei

@davidliwei davidliwei commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #52.

eval_testdata raised TypeError: PertBatchCollator.__init__() got multiple values for argument 'vocab' whenever it was called with a config derived from model.training_config.

Root cause

  • HFPerturbationTFModel.__init__ set _hub_mixin_config["vocab"] = None instead of deleting the key, then copied _hub_mixin_config into self.training_config. Every model therefore carried vocab: None in its training config, and the value round-tripped through training_config.json.
  • eval_testdata did collator_config = dict(config) and called PertBatchCollator(vocab, gene_ids, hvg_inds=hvg_inds, **collator_config), passing vocab both positionally and as a keyword.

finetune already deleted vocab from its config for this reason; eval_testdata never got the same guard.

Changes

  • perttf/model/hf.py: delete the vocab key from the hub config in __init__ rather than setting it to None. ntoken is captured on the preceding line, model.vocab is stored separately, and nothing in the package reads training_config.vocab.
  • perttf/model/train_function.py: strip vocab, gene_ids, hvg_inds, and full_tokenize from collator_config in eval_testdata, so checkpoints already saved with "vocab": null keep working.

Testing

  • Both files pass python -m py_compile.
  • No regression test added (by request). The existing pytest suite runs in CI on this PR.

🤖 Generated with Claude Code

PertTFModel.__init__ set _hub_mixin_config["vocab"] = None instead of
deleting the key, so every model's training_config carried vocab: None.
eval_testdata unpacked that config into PertBatchCollator(vocab, ...,
**collator_config), raising "got multiple values for argument 'vocab'".

- Delete the vocab key from the hub config in __init__ (ntoken is already
  captured and model.vocab is stored separately; nothing reads
  training_config.vocab).
- Strip vocab/gene_ids/hvg_inds/full_tokenize from collator_config in
  eval_testdata so checkpoints saved with "vocab": null keep working.

Fixes #52

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QhowxpBYw4dLuu1rBnRx9s
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-02T15:24:33.733378Z 51fbdc5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c91a66c8b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread perttf/model/train_function.py Outdated
Comment on lines +731 to +732
for key in ("vocab", "gene_ids", "hvg_inds", "full_tokenize"):
collator_config.pop(key, None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve full-token evaluation requests

When callers provide full_tokenize=True in config, removing this key silently changes evaluation to the collator's default False. Unlike the other keys here, full_tokenize does not collide with an explicitly supplied argument at the call below; dropping it causes evaluation to use max_seq_len and potentially omit genes instead of processing the full sequence.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 51fbdc5: the loop now strips only vocab, gene_ids, and hvg_inds, which the call supplies explicitly. full_tokenize is left in the config.

Only strip the keys the collator call supplies explicitly (vocab,
gene_ids, hvg_inds). full_tokenize is not passed by eval_testdata, so
removing it silently changed a caller's full-token request to the
collator default. Addresses Codex review on #53.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QhowxpBYw4dLuu1rBnRx9s
@davidliwei

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 51fbdc5f57

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@davidliwei
davidliwei merged commit 6bc424e into main Sep 2, 2026
4 checks passed
@davidliwei
davidliwei deleted the fix/eval-testdata-vocab-collision branch September 2, 2026 15:27
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.

eval_testdata fails: PertBatchCollator got multiple values for argument 'vocab'

1 participant