Skip to content

fix: --config mode model_type and token ID propagation - #152

Merged
justinchuby merged 3 commits into
mainfrom
justinchu/fix-config-mode
Apr 10, 2026
Merged

justinchuby merged 3 commits into
mainfrom
justinchu/fix-config-mode

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Fixes model.type=unknown and missing bos/eos token IDs when using local --config path. Addresses Issues 1 and 2 from Edge LLM evaluation.

Problem

When building with --config <local_dir> instead of a HuggingFace model ID:

  1. Issue 1: genai_config.json always contained "type": "unknown" because ArchitectureConfig had no model_type field — it was read from the HF config but never stored.

  2. Issue 2: bos_token_id / eos_token_id were absent from genai_config.json because token IDs were only fetched via AutoConfig.from_pretrained(), which is skipped when hf_model_id=None.

Fix

  • Added model_type, bos_token_id, eos_token_id fields to ArchitectureConfig
  • Populated them in from_transformers() (called by the --config path)
  • In write_ort_genai_config(), the else branch (no hf_model_id) now reads all three from ArchitectureConfig instead of leaving them as None

Tests

  • _configs_test.py: verifies from_transformers() stores the new fields
  • auto_export_test.py: two new tests — test_config_mode_model_type_propagated and test_config_mode_token_ids_propagated

Add model_type, bos_token_id, and eos_token_id fields to
ArchitectureConfig and populate them in from_transformers().

Previously, write_ort_genai_config() with hf_model_id=None (i.e.
--config mode) would produce model.type='unknown' in genai_config.json
because ArchitectureConfig had no model_type field, and the bos/eos
token IDs would be absent because they were only fetched via
AutoConfig.from_pretrained().

Fixes:
- Issue 1: ArchitectureConfig now stores model_type; the else-branch
  in write_ort_genai_config reads it to resolve the ORT-GenAI type.
- Issue 2: ArchitectureConfig stores bos_token_id/eos_token_id from
  the HF config; the else-branch reads them for genai_config.json.
  pad_token_id already present in BaseModelConfig is also forwarded.

Tests added for both code paths in auto_export_test.py and a new
from_transformers test in _configs_test.py.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@github-actions

github-actions Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 1a6e048 → 1d9f632

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 61 61 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 107 107 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 53 53 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 61 61 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 58 58 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 360 KB 360 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 103 103 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 61 61 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 58 58 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 61 61 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 58 58 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 409 409 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 174 174 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

@codecov

codecov Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 1a6e048 → 1d9f632

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 0 ⚪
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 0 ⚪
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

Copilot AI 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.

Pull request overview

This PR fixes ORT-GenAI export behavior when building from a local --config directory by ensuring the model type and special token IDs are preserved on ArchitectureConfig and then propagated into genai_config.json without requiring a HuggingFace Hub lookup.

Changes:

  • Add model_type, bos_token_id, and eos_token_id fields to ArchitectureConfig and populate them in ArchitectureConfig.from_transformers().
  • Update ORT-GenAI config generation to fall back to ArchitectureConfig for model_type and BOS/EOS/PAD token IDs when hf_model_id=None (config-mode).
  • Add unit tests covering config-mode propagation for model.type and special token IDs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/mobius/integrations/ort_genai/auto_export.py Reads model type + token IDs from ArchitectureConfig when hf_model_id is not provided.
src/mobius/integrations/ort_genai/auto_export_test.py Adds unit tests validating config-mode model type and token ID propagation into genai_config.json.
src/mobius/_configs.py Extends ArchitectureConfig with model_type/BOS/EOS fields and populates them from HF configs.
src/mobius/_configs_test.py Adds a unit test verifying the new fields are preserved by from_transformers().

justinchuby and others added 2 commits April 10, 2026 11:21
- Expand comment on _pad < 0 guard to mention DEFAULT_INT (-42) and
  why negative IDs are treated as unset
- Add test_config_mode_eos_token_id_as_list to cover list[int] eos
  (e.g. Gemma multi-stop token case)

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
- Warning now says 'missing, None, or not mapped' and logs raw_type (%r)
  so users can diagnose which value caused the fallback to 'unknown'
- Update hf_model_id param docstring to describe the new config-field
  fallback (bos/eos/pad read from ArchitectureConfig when hf_model_id
  is None) instead of the old 'defaults to None' description

Addresses Copilot review comments on PR #152.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby justinchuby added the ai Created by an AI agent label Apr 10, 2026
@justinchuby
justinchuby merged commit 170f28a into main Apr 10, 2026
20 of 22 checks passed
@justinchuby
justinchuby deleted the justinchu/fix-config-mode branch April 10, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Created by an AI agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants