Skip to content

fix(trt_llm): BEI max_num_tokens upgrade is a no-op - #2559

Open
chuenchen309 wants to merge 1 commit into
basetenlabs:mainfrom
chuenchen309:fix/bei-max-num-tokens-upgrade-noop
Open

fix(trt_llm): BEI max_num_tokens upgrade is a no-op#2559
chuenchen309 wants to merge 1 commit into
basetenlabs:mainfrom
chuenchen309:fix/bei-max-num-tokens-upgrade-noop

Conversation

@chuenchen309

Copy link
Copy Markdown

What

_bei_specfic_migration logs that it is raising max_num_tokens to the BEI minimum, but the value never changes:

TrussTRTLLMBuildConfiguration(base_model="encoder", max_num_tokens=1024, checkpoint_repository=...)
# WARNING  truss.base.trt_llm_config: build.max_num_tokens=1024, upgrading to 16384
# .max_num_tokens -> 1024

The upgrade rebinds the local name instead of assigning the field:

self = self.model_copy(update={"max_num_tokens": BEI_REQUIRED_MAX_NUM_TOKENS})

model_copy returns a new object; rebinding self inside model_post_init discards it when the method returns.

Why this looks like a slip rather than intent

  • The next two lines of the same method assign fields directly and do stick:
    self.plugin_configuration.paged_kv_cache = False
    self.plugin_configuration.use_paged_context_fmha = False
    One method, two behaviours.
  • The only other model_copy in the file assigns the result back to a field:
    self.runtime = self.runtime.model_copy(update={"webserver_default_route": route})
  • The logger.warning announces an upgrade that then doesn't happen.

Impact

serving_image_builder.py notes it is "enforcing max_num_tokens here and in engine-builder". The engine-builder half is what silently doesn't apply: the router is configured for the BEI minimum while the engine is built for the user's lower value.

Fix

Assign the field. Verified across the paths:

base_model input after
encoder 1024 16384 ✅
encoder 8192 (default) 16384 ✅
encoder 16384 16384 ✅
decoder 1024 1024 (unchanged) ✅

The adjacent paged_kv_cache = False still applies.

Tests

Two cases: the encoder path upgrades, the decoder path does not. The encoder one fails on main and passes here. grep max_num_tokens truss/tests/ previously returned nothing — the field had no coverage, which is why this went unnoticed.

  • pytest truss/tests/trt_llm/ — 23 passed, 1 skipped
  • Full non-Docker suite — 1090 passed (1088 baseline + 2 new), no regressions
  • uv run ruff check / ruff format --check clean, per AGENTS.md

AI disclosure: drafted with Claude Code (Opus 4.8), including the root-cause trace and the tests. I ran the repro and the suite locally and reviewed the diff before opening.

_bei_specfic_migration logs that it is raising max_num_tokens to the BEI
minimum, but rebinds the local name instead of assigning the field:

    self = self.model_copy(update={"max_num_tokens": BEI_REQUIRED_MAX_NUM_TOKENS})

The copy is discarded when the method returns, so the value stays as the user
set it:

    TrussTRTLLMBuildConfiguration(base_model="encoder", max_num_tokens=1024, ...)
    WARNING  build.max_num_tokens=1024, upgrading to 16384
    .max_num_tokens  # 1024

Two things show this is a slip rather than intent. The next two lines of the
same method assign fields directly and do stick
(plugin_configuration.paged_kv_cache = False). And the only other model_copy
in the file assigns the result back to a field:

    self.runtime = self.runtime.model_copy(update={...})

Assign the field. Non-encoder builds are unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cretz cretz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution! One question below and also CLA will need to be signed (click link above), thanks!

self = self.model_copy(
update={"max_num_tokens": BEI_REQUIRED_MAX_NUM_TOKENS}
)
self.max_num_tokens = BEI_REQUIRED_MAX_NUM_TOKENS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix!

Can you help me understand how you came across this bug? Specifically the steps you took on the platform to trigger it?

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.

3 participants