Repository navigation
fix: genai_config defaults and tokenizer copy for --config mode - #153
Merged
Merged
Conversation
- 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]>
Performance Comparison
|
…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]>
Contributor
There was a problem hiding this comment.
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.jsonsearch defaults (sampling enabled,max_lengthtracks context window, WebGPU setspast_present_share_buffer=True). - Add local-directory tokenizer copying for
--configmode and plumb throughwrite_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. |
Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses Issues 5 and 6 from Edge LLM evaluation.
Issue 5:
past_present_share_bufferdefaultsdo_sample: Changed fromFalsetoTrueto match production reference configs (e.g.testdata/qwen2_5_genai_config/genai_config.json)max_length: Changed from hardcoded4096tocontext_length(derived from the model'smax_position_embeddings)past_present_share_buffer: Set toTruefor WebGPU EP — the WebGPU runtime allocates a fixed KV-cache buffer up-front and requires past/present tensors to share backing memoryIssue 6: Tokenizer files not copied with
--config_copy_tokenizer_files_from_local(source_dir, output_dir)that copies tokenizer files from a local directorywrite_ort_genai_config()gains alocal_config_pathparameter; whenhf_model_idisNoneandlocal_config_pathis set, tokenizer files are copied from the local directory_save_package()in the CLI now passesargs.configaslocal_config_path--runtimehelp text to document both modesTests
genai_config_test.py: fixeddo_sampleassertion, added WebGPU/CUDA tests forpast_present_share_bufferandmax_lengthTestCopyTokenizerFilesFromLocalandTestWriteOrtGenaiConfigLocalPathtest classes toauto_export_test.pyAll 2419 tests pass.