Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only include necessary information in prompt for GenAI metrics #10698

Merged
merged 4 commits into from
Jan 3, 2024

Conversation

rmalani-db
Copy link
Collaborator

@rmalani-db rmalani-db commented Dec 14, 2023

Related Issues/PRs

What changes are proposed in this pull request?

Add an include_input parameter to the make_genai_metric() method to allow custom metrics that only need output and context to exclude the input, allowing for a shorter prompt with only relevant information. The parameter defaults to True for backward compatibility, and users can specify False to exclude the input.

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.
  • Yes. I've updated:
    • Examples
    • API references
    • Instructions

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/artifacts: Artifact stores and artifact logging
  • area/build: Build and test infrastructure for MLflow
  • area/deployments: MLflow Deployments client APIs, server, and third-party Deployments integrations
  • area/docs: MLflow documentation pages
  • area/examples: Example code
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/recipes: Recipes, Recipe APIs, Recipe configs, Recipe Templates
  • area/projects: MLproject format, project running backends
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/server-infra: MLflow Tracking server backend
  • area/tracking: Tracking Service, tracking client APIs, autologging

Interface

  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/docker: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
  • area/sqlalchemy: Use of SQLAlchemy in the Tracking Service or Model Registry
  • area/windows: Windows support

Language

  • language/r: R APIs and clients
  • language/java: Java APIs and clients
  • language/new: Proposals for new client languages

Integrations

  • integrations/azure: Azure and Azure ML integrations
  • integrations/sagemaker: SageMaker integrations
  • integrations/databricks: Databricks integrations

How 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" section
  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

Copy link

github-actions bot commented Dec 14, 2023

Documentation preview for b4e12c7 will be available here when this CircleCI job completes successfully.

More info

@rmalani-db rmalani-db marked this pull request as ready for review December 14, 2023 18:41
@github-actions github-actions bot added the rn/none List under Small Changes in Changelogs. label Dec 15, 2023
Roshni Malani added 2 commits December 19, 2023 12:05
@rmalani-db rmalani-db force-pushed the ML-36162 branch 2 times, most recently from 737d440 to f8eda62 Compare December 19, 2023 21:07
@rmalani-db
Copy link
Collaborator Author

@prithvikannan @annzhang-db Ready for review. Thanks!

Copy link
Collaborator

@sunishsheth2009 sunishsheth2009 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbczumar Can you help review this as well. Wanted to confirm on the API changes here and see if those makes sense or the suggestions made have more opinions.

Thank you @rmalani-db for working through this, sorry for the back and forth

@@ -229,6 +231,7 @@ def process_example(example):
name,
definition,
grading_prompt,
include_input,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 243 in eval_fn as args, should we remove inputs as a required field that is passed to the eval_fn?
That also means that in the signature it is optional. Thoughts?

@@ -72,17 +72,23 @@ def _format_grading_context(self):
else:
return self.grading_context

def __str__(self) -> str:
def print(self, include_input: bool = True) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we are using include_input in example rather than just not passing in input? Basically making input as optional here? Sorry maybe I missed this decision :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make input be optional here in EvaluationExample, but users can still provide it (in the case they are sharing examples between different metrics). We should still exclude the input if the metric excludes it. I believe that's the decision in Option C in the linked Jira ticket.

@@ -64,6 +84,7 @@ class EvaluationModel:
name: str
definition: str
grading_prompt: str
include_input: bool = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to change this here as well? If we just don't pass in input to the evaluation_model it doesn't render it. We can do it similar to grading_context_columns. Basically we can try and avoid adding more APIs.

@rmalani-db rmalani-db force-pushed the ML-36162 branch 4 times, most recently from 66bfa85 to 0f509bd Compare December 21, 2023 20:15
Copy link
Collaborator Author

@rmalani-db rmalani-db left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to simplify the API surface affected by the optional include_input parameter. In the process, I also simplified how PromptTemplate works to allow for optional variables that are None. Please take another look @sunishsheth2009, thanks.

@@ -72,17 +72,23 @@ def _format_grading_context(self):
else:
return self.grading_context

def __str__(self) -> str:
def print(self, include_input: bool = True) -> str:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make input be optional here in EvaluationExample, but users can still provide it (in the case they are sharing examples between different metrics). We should still exclude the input if the metric excludes it. I believe that's the decision in Option C in the linked Jira ticket.

@@ -280,7 +290,9 @@ def eval_fn(
)
grading_payloads.append(
evaluation_context["eval_prompt"].format(
input=input, output=output, grading_context_columns=arg_string
input=(input if include_input else None),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the eval context doesn't need to have an explicit include_input parameter.

@rmalani-db rmalani-db merged commit 2aa052e into master Jan 3, 2024
36 checks passed
@rmalani-db rmalani-db deleted the ML-36162 branch January 3, 2024 18:00
annzhang-db pushed a commit to annzhang-db/mlflow that referenced this pull request Jan 3, 2024
B-Step62 pushed a commit to B-Step62/mlflow that referenced this pull request Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn/none List under Small Changes in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants