forked from stanfordnlp/dspy
-
Notifications
You must be signed in to change notification settings - Fork 3
Add reference doc for databricks.py, avatar.py and simba_utils.py #7
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
Open
banana-bison
wants to merge
2
commits into
swe-productivity:main
Choose a base branch
from
banana-bison:refdoc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,22 @@ def prepare_models_for_resampling(program: dspy.Module, n: int, teacher_settings | |
| return models | ||
|
|
||
| def wrap_program(program: dspy.Module, metric: Callable): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we also add type hint?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function (wrap_program), already has type hints. Did you mean the function below it: wrapped_program? |
||
| def wrapped_program(example): | ||
| """ | ||
| Wraps a program into a function that returns a dictionary of various metrics | ||
|
|
||
| Args: | ||
| program (dspy.Module): dspy.Module that contains instructions to run the LM. | ||
| metric (Callable[str,str]): A function that takes examples from your data and output of the LM and compares them | ||
| Returns: | ||
| A functions that take a dspy.Example as argument and returns a dict with the following keys when called: { | ||
| "prediction", | ||
| "trace", | ||
| "score", | ||
| "example", | ||
| "output_metadata", | ||
| } | ||
| """ | ||
| def wrapped_program(example: dspy.Example): | ||
| with dspy.context(trace=[]): | ||
| prediction, trace, score = None, None, 0.0 | ||
| try: | ||
|
|
@@ -70,7 +85,22 @@ def wrapped_program(example): | |
|
|
||
| return wrapped_program | ||
|
|
||
| def append_a_demo(demo_input_field_maxlen): | ||
| def append_a_demo(demo_input_field_maxlen: int): | ||
| """ | ||
| One of the strategies (chosen at random) of the SIMBA optimizer. The other one is append_a_rule | ||
| Args: | ||
| demo_input_field_maxlen: Max length of characters in the input field | ||
| Returns: | ||
| A function of the following form: | ||
| Args: | ||
| bucket: A list of dictionaries with atleast a "score" key | ||
| system: A program selected from a list of programs on the basis of softmax sampling of top k baseline candidates | ||
| predictor2name: A dict that maps predictors to their names | ||
| name2predictor: A dict that maps names to their predictors | ||
| batch_10p_score: 10th percentile score | ||
| Returns: | ||
| bool: True if demo successful, False if bucket[0] score is less than 10th percentile | ||
| """ | ||
| def append_a_demo_(bucket, system, **kwargs): | ||
| predictor2name, name2predictor = kwargs["predictor2name"], kwargs["name2predictor"] | ||
| batch_10p_score = kwargs["batch_10p_score"] | ||
|
|
@@ -103,7 +133,18 @@ def append_a_demo_(bucket, system, **kwargs): | |
| return append_a_demo_ | ||
|
|
||
|
|
||
| def append_a_rule(bucket, system, **kwargs): | ||
| def append_a_rule(bucket: list[dict], system: dspy.Module, **kwargs): | ||
| """ | ||
| One of the strategies (chosen at random) of the SIMBA optimizer. The other one is append_a_demo | ||
| Args: | ||
| bucket: A list of dictionaries with atleast a "score" key | ||
| system: A program selected from a list of programs on the basis of softmax sampling of top k baseline candidates | ||
| predictor2name: A dict that maps predictors to their names | ||
| name2predictor: A dict that maps names to their predictors | ||
| batch_10p_score: 10th percentile score | ||
| Returns: | ||
| bool: True if demo successful, False if bucket[0] score is less than 10th percentile or greater than 90th percentile | ||
| """ | ||
| predictor2name = kwargs["predictor2name"] | ||
| batch_10p_score, batch_90p_score = kwargs["batch_10p_score"], kwargs["batch_90p_score"] | ||
| prompt_model = kwargs["prompt_model"] or dspy.settings.lm | ||
|
|
@@ -207,7 +248,13 @@ class OfferFeedback(dspy.Signature): | |
| "like the successful trajectory rather than the lower-scoring trajectory." | ||
| ) | ||
|
|
||
| def inspect_modules(program): | ||
| def inspect_modules(program: dspy.Module): | ||
| """ | ||
| Args: | ||
| program (dspy.Module): A dspy.Module | ||
| Returns: | ||
| str: A listing of input_fields and output_fields from program.named_predictors | ||
| """ | ||
| separator = "-" * 80 | ||
| output = [separator] | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is databricks store?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that databricks provides a store for ML models and dspy client for databricks provides functions to manage/use them through dspy's paradigm. The store is question is the databricks feature store https://docs.databricks.com/aws/en/machine-learning/feature-store/. Is my understanding correct?