Skip to content

Bug: TinyLlama-1.1B-Chat's e2e case produces empty output — first decode step predicts EOS immediately #1271

Closed

Description

@roma5087

Affected area

Inference output or task execution

TensorRT-Model-Connect version

296f366 (upstream/main at time of testing)

Installation method

Development container

Model and revision

TinyLlama/TinyLlama-1.1B-Chat-v1.0 at main

Environment

  • OS: Ubuntu 24.04 (container)
  • GPU: NVIDIA A40, 48GB VRAM
  • Driver: 580.159.03 (CUDA forward-compatibility mode, CUDA 13.3 userspace)
  • CUDA: 13.3
  • TensorRT: 11.1.0.106
  • Container image: nvcr.io/nvidia/tensorrt:26.07-py3, with torch==2.12.0+cu130 (matches Dockerfile.dev.x86-gpu / community GPU CI environment)

Minimal reproducer

# Build the bundle
python3.12 -c "
from pathlib import Path
from tensorrt_model_connect import BuildRequest, build
build(BuildRequest(
    model_dir=Path('/path/to/TinyLlama-1.1B-Chat-v1.0'),
    output_path=Path('/tmp/tinyllama-1.1b.bundle'),
    family='llama', task='text_generation', precision='fp16',
    max_sequence_length=256,
))
"

# Run it through the native runtime
trtmc run /tmp/tinyllama-1.1b.bundle \
  --runtime-root <build-output-dir> \
  --prompt "What is the capital of France? Answer in one word." \
  --max-new-tokens 10 \
  --use-chat-template true

This is also directly reproducible through the repository's own existing e2e
harness, without any external reproducer:

TRTMC_BINARY=<path-to-trtmc> TRTMC_RUNTIME_ROOT=<build-output-dir> \
  pytest families/llama/tests/test_e2e.py --e2e-model=tinyllama-1.1b -s

using the manifest already checked into the repository at
families/llama/tests/manifests/tinyllama-1.1b.json.

Observed behavior

The native runtime's first decode step (immediately after prefill) predicts
the EOS token, producing empty output:

{"decode_ms":0.04743,"prefill_ms":67.912788,"setup_ms":0.00046,"text":"","token_ids":[2]}

The families/llama/tests/test_e2e.py::test_e2e[tinyllama-1.1b] case fails
its correctness assertion (assert actual_text) as a result.

Expected behavior

A real HF reference generation (transformers.AutoModelForCausalLM.generate(),
same prompt, same chat template, greedy/do_sample=False) produces a
sensible, correct answer:

token_ids: [12415, 2410, 29901, 3681, 2]
text: "Capital: Paris"

The native engine's very first decode-step logits diverge sharply from the
reference at that step — this is not an EOS-matching issue (EOS=2 is the
correct id and correctly stops generation once predicted); the problem is
that EOS gets predicted immediately instead of real content.

Suspected root cause

families/llama/runtime/chat_templates.cpp's format-detection heuristic
(llama_detect_chat_template_format) substring-matches the raw Jinja
template for <|user|>/<|assistant|> role tags and classifies any template
containing them as "Phi" format. TinyLlama-1.1B-Chat's own chat template
also uses those role tags, but separates turns with its real EOS token
(</s>, id 2), not Phi's literal <|end|> turn-separator string that
apply_phi() injects. If TinyLlama's template is being misclassified as
Phi format, the rendered prompt fed to the engine would contain a
turn-separator token sequence the model was never trained on, plausibly
explaining an out-of-distribution first-step prediction. This is a
hypothesis based on reading the detection logic and is not proven with a
token-level trace of the actual rendered prompt — flagging it as a lead for
whoever investigates, not a confirmed diagnosis.

Isolation notes

This is unrelated to any pending PR. Found incidentally while
regression-testing an unrelated eos_token_id fix (#1269) against the
ordinary single-EOS case. Reproduced identically by rebuilding with the
unmodified families/llama/config.py, model.py, and runtime/plugin.cpp
from upstream/main, confirming this predates and is unrelated to that PR.
families/llama/runtime/chat_templates.cpp, pipeline.cpp, and
sampler.cpp were not modified in that PR either.

Relevant logs

[trtmc] KV cache rows=256 (bundle max=256)
[trtmc.prefill] tokens=13 launches=1 max_chunk=13
{"decode_ms":0.04743,"prefill_ms":67.912788,"setup_ms":0.00046,"text":"","token_ids":[2]}
[trtmc.engine_timing] label="llama prefill" execute_ms=56.055233 launches=1
[trtmc.engine_timing] label="llama decoder" execute_ms=12.112448 launches=1

Activity

  1. dundysm commented on Sep 12, 2026

    @dundysm
    Contributor

    i'll take this; plan is to check whether tinyllama's chat template is being misclassified as phi (role-tag heuristic) and fix format detection / rendering so the first decode isn't an immediate eos. will add a focused regression if there's a good unit seam; full gpu e2e may be limited on my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions