Skip to content

refactor(char-causal-lm): drop unreachable GenerationConfig construction - #8

Merged
AmitMY merged 1 commit into
mainfrom
simplify/drop-dead-generation-config
Jul 27, 2026
Merged

refactor(char-causal-lm): drop unreachable GenerationConfig construction#8
AmitMY merged 1 commit into
mainfrom
simplify/drop-dead-generation-config

Conversation

@AmitMY

@AmitMY AmitMY commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Small one — the cheap wins from the audit are mostly spent, so this is a narrow dead-branch removal.

What

-        if generation_config is None:
-            generation_config = GenerationConfig()
         max_new_tokens = getattr(generation_config, 'max_new_tokens', None) or 50
         min_new_tokens = getattr(generation_config, 'min_new_tokens', None) or 0

_get_generation_params built a throwaway GenerationConfig when none was passed, then immediately read it back through getattr(..., None). But:

GenerationConfig().max_new_tokens          # None
getattr(None, 'max_new_tokens', None)      # None

Both paths land on the same or 50 / or 0 fallbacks, so the constructed object could never influence the result. The None check 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, ruff clean. The GenerationConfig import 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_params that instantiated GenerationConfig() when the argument was None. The helper already reads limits via getattr(..., None) or <default>, so a fresh default config (also None for 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 TestGetGenerationParams cases (None vs empty GenerationConfig()) still cover both paths.

Reviewed by Cursor Bugbot for commit 97d3d19. Bugbot is set up for automated code reviews on this repo. Configure here.

_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>
@AmitMY
AmitMY merged commit 13fc0e0 into main Jul 27, 2026
4 checks passed
@AmitMY
AmitMY deleted the simplify/drop-dead-generation-config branch July 27, 2026 11:02
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