refactor(char-causal-lm): drop unreachable GenerationConfig construction - #8
Merged
Merged
Conversation
_get_generation_params built a throwaway GenerationConfig when none was passed, then read it back through getattr with a None default. A fresh GenerationConfig has max_new_tokens = min_new_tokens = None, and getattr(None, 'max_new_tokens', None) is also None, so both paths hit the same `or 50` / `or 0` fallbacks. The object could never change the result. The existing tests already pin this down from both sides: test_none_config asserts _get_generation_params(None) == (50, 0) and test_empty_config asserts _get_generation_params(GenerationConfig()) == (50, 0). Both still pass, unchanged. Not sold as a speed fix, though it does drop an allocation from the default generate() path: 2.74 us -> 0.06 us for that call, which is nothing next to the hundreds of model forwards a generation runs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Small one — the cheap wins from the audit are mostly spent, so this is a narrow dead-branch removal.
What
_get_generation_paramsbuilt a throwawayGenerationConfigwhen none was passed, then immediately read it back throughgetattr(..., None). But:Both paths land on the same
or 50/or 0fallbacks, so the constructed object could never influence the result. TheNonecheck was doing nothing.Verification
The existing tests already pin this from both sides, so no new test was needed and none changed:
test_none_config—_get_generation_params(None) == (50, 0)test_empty_config—_get_generation_params(GenerationConfig()) == (50, 0)241 passed,
ruffclean. TheGenerationConfigimport stays — still used by the type annotations.Not a perf claim
It does remove an allocation from the default
generate()path (2.74 µs → 0.06 µs for that call), but that is noise against the hundreds of model forwards a generation runs. Mentioning it only so the number is on record; the reason to merge is the dead branch, not the microseconds.🤖 Generated with Claude Code
Note
Low Risk
Narrow refactor with no logic change; generation limits still default to 50/0 when unset.
Overview
Removes a dead branch in
CharacterCausalLMWrapper._get_generation_paramsthat instantiatedGenerationConfig()when the argument wasNone. The helper already reads limits viagetattr(..., None) or <default>, so a fresh default config (alsoNonefor those fields) never changed the returned(50, 0)values.The docstring now states that a missing config is equivalent to a default one for those fallbacks. Behavior is unchanged; existing
TestGetGenerationParamscases (Nonevs emptyGenerationConfig()) still cover both paths.Reviewed by Cursor Bugbot for commit 97d3d19. Bugbot is set up for automated code reviews on this repo. Configure here.