Skip to content

fix: genai_config defaults and tokenizer copy for --config mode - #153

Merged
justinchuby merged 12 commits into
mainfrom
justinchu/fix-genai-defaults
Apr 10, 2026
Merged

justinchuby merged 12 commits into
mainfrom
justinchu/fix-genai-defaults

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Summary

Addresses Issues 5 and 6 from Edge LLM evaluation.

Issue 5: past_present_share_buffer defaults

  • do_sample: Changed from False to True to match production reference configs (e.g. testdata/qwen2_5_genai_config/genai_config.json)
  • max_length: Changed from hardcoded 4096 to context_length (derived from the model's max_position_embeddings)
  • past_present_share_buffer: Set to True for WebGPU EP — the WebGPU runtime allocates a fixed KV-cache buffer up-front and requires past/present tensors to share backing memory

Issue 6: Tokenizer files not copied with --config

  • Added _copy_tokenizer_files_from_local(source_dir, output_dir) that copies tokenizer files from a local directory
  • write_ort_genai_config() gains a local_config_path parameter; when hf_model_id is None and local_config_path is set, tokenizer files are copied from the local directory
  • _save_package() in the CLI now passes args.config as local_config_path
  • Updated --runtime help text to document both modes

Tests

  • Updated genai_config_test.py: fixed do_sample assertion, added WebGPU/CUDA tests for past_present_share_buffer and max_length
  • Added TestCopyTokenizerFilesFromLocal and TestWriteOrtGenaiConfigLocalPath test classes to auto_export_test.py

All 2419 tests pass.

- Set do_sample=True by default (matches production reference configs)
- Set max_length=context_length instead of hardcoded 4096
- Set past_present_share_buffer=True for WebGPU EP (required for
  fixed KV-cache buffer allocation)
- Add _copy_tokenizer_files_from_local() for local directory paths
- write_ort_genai_config() now accepts local_config_path parameter
  and copies tokenizer files from it when hf_model_id is None
- Update --runtime help text to document both --model and --config modes
- Update genai_config_test.py: fix do_sample assertion, add WebGPU
  and CUDA tests for past_present_share_buffer and max_length
- Update auto_export_test.py: add TestCopyTokenizerFilesFromLocal and
  TestWriteOrtGenaiConfigLocalPath test classes

Addresses Issues 5 and 6 from Edge LLM evaluation.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby requested review from a team and Copilot April 10, 2026 18:17
@github-actions

github-actions Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 8693678 → dcf6bef

Model Sub-model Changes Status

No architecture changes detected. ✅


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

@github-actions

github-actions Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 8693678 → dcf6bef

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 59 59 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 56 56 +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.

…location

When past_present_share_buffer=True (WebGPU EP), ORT GenAI pre-allocates
the full KV-cache for max_length tokens at model load time.  Using the raw
context_length (e.g. 128K for Llama 3.1) would pre-allocate ~8.4 GB of
GPU memory by default, making the model unusable on consumer hardware.

Cap max_length at min(context_length, 4096) for WebGPU so the model loads
with a sensible default.  Users who need a longer generation window can
override max_length in their genai_config.json.

Non-WebGPU EPs are unaffected: max_length continues to track context_length.

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

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

Updates ORT-GenAI config generation to better match production defaults and ensures tokenizer artifacts are included when exporting from a local --config directory.

Changes:

  • Update genai_config.json search defaults (sampling enabled, max_length tracks context window, WebGPU sets past_present_share_buffer=True).
  • Add local-directory tokenizer copying for --config mode and plumb through write_ort_genai_config(..., local_config_path=...) from the CLI.
  • Expand unit tests to cover new defaults and local tokenizer copy behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/mobius/integrations/ort_genai/genai_config.py Adjusts default search params based on EP and model context length.
src/mobius/integrations/ort_genai/genai_config_test.py Updates assertions and adds coverage for WebGPU/CUDA behavior and max_length.
src/mobius/integrations/ort_genai/auto_export.py Adds local tokenizer file copy helper and integrates it into write_ort_genai_config.
src/mobius/integrations/ort_genai/auto_export_test.py Adds tests for local tokenizer copying and precedence vs HF download.
src/mobius/__main__.py Passes --config path through to runtime config generation and updates --runtime help text.

@justinchuby justinchuby added the ai Created by an AI agent label Apr 10, 2026
justinchuby and others added 3 commits April 10, 2026 11:24
…missing dir

- Rename local_config_path parameter to local_config_dir throughout
  (auto_export.py, __main__.py, auto_export_test.py) — it's a directory,
  not a file path
- Add comment in write_ort_genai_config() making explicit that HF Hub
  takes precedence over local_config_dir when both are supplied
- Emit logger.warning when source_dir passed to
  _copy_tokenizer_files_from_local does not exist, rather than silently
  returning an empty list — makes misconfigured --config paths visible
- Add test_missing_source_dir_warns_and_returns_empty to cover the warning

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Instead of hardcoding 'ep == webgpu' in genai_config.py, the flag is now
a first-class field on EpCapabilities and read from ep_registry at
config-generation time.

Changes:
- EpCapabilities: add past_present_share_buffer: bool = False field with
  docstring explaining the WebGPU KV-cache pre-allocation requirement
- WebGPU entry in _register_builtins: set past_present_share_buffer=True
- _default_search_params(): replace 'ep == webgpu' with
  ep_registry.get(ep).past_present_share_buffer (falls back to False for
  unregistered EPs)
- max_length cap logic now triggers on share_buffer, not on ep name,
  so any future EP that pre-allocates KV-cache benefits automatically
- genai_config_test.py: update WebGPU test docstrings; add
  test_search_params_custom_ep_with_share_buffer that registers a synthetic
  EP with past_present_share_buffer=True and verifies the flag and cap fire
  without any hardcoded name check

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
The cap is now triggered by the share_buffer capability flag, not
specifically by the WebGPU EP name.

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

codecov Bot commented Apr 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.48485% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mobius/integrations/ort_genai/auto_export.py 90.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

justinchuby and others added 6 commits April 10, 2026 11:38
…efaults

Signed-off-by: Justin Chu <[email protected]>

# Conflicts:
#	src/mobius/integrations/ort_genai/auto_export.py
Signed-off-by: Justin Chu <[email protected]>
The branch fully contains origin/main (fast-forward merge confirmed
locally). This empty commit forces GitHub to re-check mergeability.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
…efaults

Signed-off-by: Justin Chu <[email protected]>

# Conflicts:
#	src/mobius/components/_mlp.py
#	src/mobius/models/base.py
…ities field

Rename EpCapabilities.past_present_share_buffer to
supports_past_present_share_buffer for consistency with other
capability flags.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby merged commit db7c0ca into main Apr 10, 2026
21 of 22 checks passed
@justinchuby
justinchuby deleted the justinchu/fix-genai-defaults branch April 10, 2026 20:38
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