Skip to content

Export Issue with SmolLM2 [ARM Example] #22518

Closed

Description

@west9906

🐛 Describe the bug

lm_eval WikiText calibration fails with HuggingFaceTokenizer when bos_id=None

When running SmolLM2 PT2E quantization with WikiText calibration, lm_eval enters loglikelihood_rolling() and fails while sorting requests because the rolling-window prefix token becomes None.

The issue is caused by EagerEvalWrapper.prefix_token_id checking whether bos_id exists rather than whether it has a valid value.

Reproduction

examples/arm/smollm2_example_ethos_u/export_smollm2_ethosu.sh \
  --mode=w8a16 \
  --use-kv-cache \
  --max_seq_length=64 \
  --max_context_length=64 \
  --calibration_limit=1 \
  --calibration_seq_length=64 \
  --quantize_scope=linear

The failure occurs during:

pt2e_quantize
  -> pt2e_calibrate
  -> lm_eval.simple_evaluate
  -> HFLM.loglikelihood_rolling
  -> HFLM._loglikelihood_tokens
  -> Collator.get_batched
  -> Collator._reorder
  -> sorted(...)

with:

TypeError: '<' not supported between instances of 'int' and 'NoneType'

Root cause

The calibration code obtains the tokenizer with:

from pytorch_tokenizers import get_tokenizer

tokenizer = get_tokenizer(tokenizer_path)

For the SmolLM2 tokenizer, the resulting object is:

<class 'pytorch_tokenizers.hf_tokenizer.HuggingFaceTokenizer'>

Its special-token IDs are:

  • bos_id: None
  • eos_id: 0
  • eot_id: None

The current EagerEvalWrapper implementation contains:

@property
def eot_token_id(self):
    if hasattr(self._tokenizer, "eot_id"):
        return self._tokenizer.eot_id
    return self._tokenizer.eos_id

@property
def prefix_token_id(self):
    if hasattr(self._tokenizer, "bos_id"):
        return self._tokenizer.bos_id
    return self.eot_token_id

Because bos_id exists as an attribute but its value is None:

hasattr(self._tokenizer, "bos_id") == True
self._tokenizer.bos_id == None

the prefix_token_id property returns None.

lm_eval then creates a rolling window with:

context = [None]

and eventually attempts to sort token sequences containing both integers and None, resulting in:

TypeError: '<' not supported between instances of 'int' and 'NoneType'

Proposed fix

Use the value of the attribute rather than only checking whether the attribute exists:

@property
def eot_token_id(self):
    eot_id = getattr(self._tokenizer, "eot_id", None)
    if eot_id is not None:
        return eot_id
    return self._tokenizer.eos_id

@property
def prefix_token_id(self):
    bos_id = getattr(self._tokenizer, "bos_id", None)
    if bos_id is not None:
        return bos_id
    return self.eot_token_id

For this tokenizer this resolves to:

bos_id = None
eot_id = None
eos_id = 0

prefix_token_id = 0

After applying this change, the NoneType sorting exception no longer occurs and WikiText calibration proceeds into loglikelihood_rolling.

Additional observation

The raw SmolLM2 tokenizer.json contains <|endoftext|> as a special token, and the ExecuTorch tokenizer reports:

eos_id = 0

so EOS is available even though BOS is not.

This suggests that the issue is specifically the hasattr() handling in EagerEvalWrapper, rather than a missing EOS token in the tokenizer.

Expected behavior

If a tokenizer exposes:

bos_id = None
eos_id = 0

the lm-eval integration should use the available EOS/EOT token as the rolling likelihood prefix rather than returning None.

Versions

PyTorch version: 2.13.0+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 24.04.4 LTS (x86_64)
GCC version: (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version: 17.0.6 (9ubuntu1)
CMake version: version 3.31.10
Libc version: glibc-2.39

Python version: 3.10.21 (main, Aug 27 2026, 14:42:07) [GCC 14.3.0] (64-bit runtime)
Python platform: Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.39
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: False
Caching allocator config: N/A

Versions of relevant libraries:
[pip3] executorch==1.5.0+2b6ae07
[pip3] numpy==2.2.6
[pip3] pytorch_tokenizers==1.3.0
[pip3] torch==2.13.0+cpu
[pip3] torchao==0.18.0.dev20260729+cpu
[pip3] torchaudio==2.11.0+cpu
[pip3] torchdata==0.11.0+cpu
[pip3] torchsr==1.0.4
[pip3] torchtune==0.0.0
[pip3] torchvision==0.28.0+cpu
[conda] executorch 1.5.0+2b6ae07 pypi_0 pypi
[conda] numpy 2.2.6 pypi_0 pypi
[conda] pytorch-tokenizers 1.3.0 pypi_0 pypi
[conda] torch 2.13.0+cpu pypi_0 pypi
[conda] torchao 0.18.0.dev20260729+cpu pypi_0 pypi
[conda] torchaudio 2.11.0+cpu pypi_0 pypi
[conda] torchdata 0.11.0+cpu pypi_0 pypi
[conda] torchsr 1.0.4 pypi_0 pypi
[conda] torchtune 0.0.0 pypi_0 pypi
[conda] torchvision 0.28.0+cpu pypi_0 pypi

cc @mergennachin @iseeyuan @lucylq @helunwencser @tarun292 @kimishpatel @jackzhxng @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani @larryliu0820 @cccclai

Activity

  1. fatih-uzlmz commented on Sep 3, 2026

    @fatih-uzlmz
    Contributor

    Hi @west9906 and @nil-is-all ll, I’d like to work on this if it’s available!

    I can update the BOS/EOT fallback logic and then add regression coverage for the SmolLM2 tokenizer case. Is anyone working on a fix? if not I can jump in :)

  2. abhinav-phi commented on Sep 4, 2026

    @abhinav-phi

    Hi! I'd like to work on this.

    Plan: I'll investigate the reported behavior, implement the change/fix per the issue description, and add tests to cover it.

    Could you please assign this issue to me? Thanks!

    /assign take

  3. added theissue type on Sep 8, 2026
  4. added
    module: llm
    on Sep 8, 2026
  5. nil-is-all commented on Sep 8, 2026

    @nil-is-all
    Contributor

    Hi @west9906, thanks for the detailed report. If @fatih-uzlmz could put up a PR and tag it here, we can review it.
    @abhinav-phi let's wait and see if they reply. I can assign if they don't

  6. added
    module: examples
    triaged
    on Sep 8, 2026
  7. fatih-uzlmz commented on Sep 9, 2026

    @fatih-uzlmz
    Contributor

    Hi @nil-is-all, thanks for the go-ahead. I opened #22633 with the None-aware BOS/EOT fallback and focused regression coverage.

  8. fatih-uzlmz commented on Sep 9, 2026

    @fatih-uzlmz
    Contributor

    Also added coverage to make sure token ID 0 is treated as valid for BOS/EOT/EOS, along with the None and missing ID fallback cases.

    Went ahead and signed the CLA as well, everything should be good on my end! Thanks again for assigning this issue to me!

  9. added
    partner: arm
    on Sep 9, 2026
  10. added a commit that references this issue on Sep 10, 2026
    9ad8f1f
  11. moved this from To triage to Done in ExecuTorch Coreon Sep 10, 2026
  12. added
    module: arm
    on Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

module: armmodule: examplesmodule: llmpartner: armtriaged

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions