Add model config to prompt (backend and docs change)#19174
Add model config to prompt (backend and docs change)#19174chenmoneygithub merged 15 commits intomlflow:masterfrom
Conversation
|
@chenmoneygithub Thank you for the contribution! Could you fix the following issue(s)? ⚠ DCO checkThe DCO check failed. Please sign off your commit(s) by following the instructions here. See https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.md#sign-your-work for more details. |
|
/review ✅ Review completed. Review OutputReview CompleteI've reviewed PR #19174 "Add model config to prompt (backend and docs change)" and found 3 issues:
All comments have been posted to the PR with suggested fixes. The overall code quality is good, with comprehensive tests, proper validation, and clear documentation. The implementation correctly handles model configuration as a mutable property stored in tags. |
There was a problem hiding this comment.
Pull request overview
This PR adds model configuration support to the MLflow Prompt Registry, allowing users to store model-specific settings (e.g., model name, temperature, max_tokens) alongside prompt templates. This ensures reproducibility by versioning both prompts and their associated model parameters together.
Key Changes:
- Introduces a new
PromptModelConfigdataclass with validation for common LLM parameters (temperature, max_tokens, top_p, etc.) - Adds
model_configparameter to prompt registration and management APIs - Implements
set_prompt_model_config()anddelete_prompt_model_config()for mutable model configuration management
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
mlflow/entities/model_registry/prompt_version.py |
Adds PromptModelConfig dataclass with validation and model_config property to PromptVersion |
mlflow/entities/model_registry/__init__.py |
Exports PromptModelConfig for public API |
mlflow/genai/prompts/__init__.py |
Adds model_config parameter to register_prompt() and new functions set_prompt_model_config() and delete_prompt_model_config() |
mlflow/genai/__init__.py |
Exports new model config management functions |
mlflow/tracking/client.py |
Adds model_config parameter support in client's register_prompt() method |
mlflow/tracking/_model_registry/fluent.py |
Adds model_config parameter support in fluent API |
mlflow/store/model_registry/abstract_store.py |
Implements model_config handling in create_prompt_version() |
mlflow/store/_unity_catalog/registry/rest_store.py |
Implements model_config handling for Unity Catalog backend |
tests/genai/prompts/test_prompts.py |
Comprehensive tests for model config registration, loading, updating, and deletion |
tests/entities/test_prompt.py |
Unit tests for PromptModelConfig validation, serialization, and integration |
docs/docs/genai/prompt-registry/index.mdx |
Extensive documentation covering model config usage, validation, and provider-specific parameters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/review rewrite ✅ Review completed. Review OutputI've completed the PR review for PR #19174. Here's a summary of the issues found and comments added: Review Summary5 comments added:
All comments follow the requested focus areas and include the "🤖 Generated with Claude Code" signature. |
mlflow/genai/prompts/__init__.py
Outdated
| registry_api._load_prompt_cached.cache_clear() | ||
|
|
||
|
|
||
| @experimental(version="3.5.0") |
There was a problem hiding this comment.
I am using 3.8.0, which is the next minor release, let me know if that's the correct approach!
| PromptVersionTag = ModelVersionTag | ||
|
|
||
|
|
||
| MODEL_CONFIG_TAG_KEY = "_mlflow_prompt_model_config" |
There was a problem hiding this comment.
Lets rename the key to follow mlflow/utils/mlflow_tags.py, and move it in this file
| from pydantic import BaseModel, Field | ||
|
|
||
|
|
||
| class PromptModelConfig(BaseModel): |
There was a problem hiding this comment.
Functionality-wise a wildcard dict can do the job, but I don't like that approach, which has no validation and format constraint. Also it's hard to document it in the docstring: model_config: dict[str, Any] is confusing.
tests/entities/test_prompt.py
Outdated
| # Test valid values | ||
| PromptModelConfig(temperature=0.0, max_tokens=1000, top_p=0.9, top_k=50) |
There was a problem hiding this comment.
| # Test valid values | |
| PromptModelConfig(temperature=0.0, max_tokens=1000, top_p=0.9, top_k=50) | |
| def test_... | |
| # Test valid values | |
| PromptModelConfig(temperature=0.0, max_tokens=1000, top_p=0.9, top_k=50) |
can we separate this test?
There was a problem hiding this comment.
this line is actually redundant, and has been covered by other test cases, removed!
mlflow/utils/mlflow_tags.py
Outdated
| LATEST_CHECKPOINT_ARTIFACT_TAG_KEY = "mlflow.latest_checkpoint_artifact" | ||
|
|
||
| # For prompt model configuration | ||
| MLFLOW_PROMPT_MODEL_CONFIG = "_mlflow_prompt_model_config" |
There was a problem hiding this comment.
can we use the same format as other tags?
There was a problem hiding this comment.
oops, missed this one, thanks for catching!
| frequency_penalty: float | None = None | ||
| presence_penalty: float | None = None | ||
| stop_sequences: list[str] | None = None | ||
| extra_params: dict[str, Any] = Field(default_factory=dict) |
There was a problem hiding this comment.
can extra_params contain the known fields?
There was a problem hiding this comment.
yes good question - it's allowed and would work fine, but not the good practice because it can break the UI rendering or so.
harupy
left a comment
There was a problem hiding this comment.
Left a few more comments/questions, otherwise LGTM :)
harupy
left a comment
There was a problem hiding this comment.
Left a few more comments, otherwise LGTM!
| known_fields = { | ||
| "model_name", | ||
| "temperature", | ||
| "max_tokens", | ||
| "top_p", | ||
| "top_k", | ||
| "frequency_penalty", | ||
| "presence_penalty", | ||
| "stop_sequences", | ||
| } |
There was a problem hiding this comment.
Any pydantic model field we can leverage to de-hardcode these?
There was a problem hiding this comment.
yes good call!
|
Documentation preview for cc4fc4f is available at: Changed Pages (1)
More info
|
| ) | ||
| """ | ||
|
|
||
| model_name: str | None = None |
There was a problem hiding this comment.
@chenmoneygithub Sorry for the late review! How do you feel about making model_name required? I think it's unlikely that users want to configure other parameters without configuring model name. Also as we discussed, can we add provider name?
| LATEST_CHECKPOINT_ARTIFACT_TAG_KEY = "mlflow.latest_checkpoint_artifact" | ||
|
|
||
| # For prompt model configuration | ||
| MLFLOW_PROMPT_MODEL_CONFIG = "mlflow.prompt.modelConfig" |
There was a problem hiding this comment.
@chenmoneygithub Can we replace "." with "_" and move this config to mlflow/prompt/constants.py? Managed prompt registry does not allow to have "." in the tag key name.
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#xxxWhat changes are proposed in this pull request?
Prompt should have model configs, because models use different prompts.
How is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.