Skip to content

Add genie_overrides to QairtEncapsulation for GenAIConfig customization#2469

Draft
qti-kromero wants to merge 1 commit into
microsoft:mainfrom
CodeLinaro:dev/qti-kromero/qairt-encapsulation-genie-overrides
Draft

Add genie_overrides to QairtEncapsulation for GenAIConfig customization#2469
qti-kromero wants to merge 1 commit into
microsoft:mainfrom
CodeLinaro:dev/qti-kromero/qairt-encapsulation-genie-overrides

Conversation

@qti-kromero
Copy link
Copy Markdown
Contributor

Introduce a genie_overrides PassConfigParam that deep-merges user-supplied fields into the GenAIConfig before LLMContainer.export() bakes them into the Genie DLC. This allows callers to override any GenAIConfig field (engine config, positional encoding, etc.) without modifying QairtGenAIBuilder or QairtPipelinePass.

Nested dicts are merged recursively so only the specified keys are changed; all other values set by the upstream builder pass are preserved.

Describe your changes

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary.
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.

(Optional) Issue link

Introduce a genie_overrides PassConfigParam that deep-merges user-supplied
fields into the GenAIConfig before LLMContainer.export() bakes them into the
Genie DLC. This allows callers to override any GenAIConfig field (engine config,
positional encoding, etc.) without modifying QairtGenAIBuilder or QairtPipelinePass.

Nested dicts are merged recursively so only the specified keys are changed;
all other values set by the upstream builder pass are preserved.
container: qairt_genai.LLMContainer = qairt_genai.LLMContainer.load(model.model_path)

if config.genie_overrides:
gen_ai_cfg = container._gen_ai_config
gen_ai_cfg = container._gen_ai_config
current = gen_ai_cfg.model_dump(mode="json", by_alias=False, exclude_none=True)
merged = _deep_merge(current, config.genie_overrides)
container._gen_ai_config = gen_ai_cfg.model_validate(merged)
"kv_dim": None,
"positional_encoding": {"type": "rope", "rope_dim": 64},
}
mock_container._gen_ai_config.model_dump.return_value = initial_gen_ai_state
encap_pass.run(mock_qairt_model, str(output_path))

# model_dump was called to capture current state
mock_container._gen_ai_config.model_dump.assert_called_once_with(mode="json", by_alias=False, exclude_none=True)
"kv_dim": 128,
"positional_encoding": {"type": "rope", "rope_dim": 64, "rope_theta": 500000.0},
}
mock_container._gen_ai_config.model_validate.assert_called_once_with(expected_merged)
mock_container._gen_ai_config.model_validate.assert_called_once_with(expected_merged)
# _gen_ai_config was reassigned to the validated result
assert (
mock_container._gen_ai_config
# _gen_ai_config was reassigned to the validated result
assert (
mock_container._gen_ai_config
is not mock_qairt_modules["gen_ai_api"].LLMContainer.load.return_value._gen_ai_config

encap_pass.run(mock_qairt_model, str(output_path))

mock_container._gen_ai_config.model_dump.assert_not_called()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants