-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add model_prompt
config param for LLMBlock
#141
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2363dfe
docs: Add a doc to track pipeline config version history
russellb 87871d3
llmblock: add `model_prompt` config parameter
russellb 4f042ae
Add test case for LLMBlock model_prompt parameter
russellb 7045456
llmblock: allow model_prompt=""
markmc 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 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Pipeline Configuration | ||
|
||
Built-in pipeline configurations can be found in [`src/instructlab/sdg/pipelines/`](../src/instructlab/sdg/pipelines/). | ||
|
||
## Pipeline Configuration Schema | ||
|
||
A schema for validating pipeline configuration can be found in [`src/instructlab/sdg/pipelines/schema/v1.json`](../src//instructlab/sdg/pipelines/schema/v1.json) | ||
|
||
## Version History | ||
|
||
| Version | Description | | ||
| --- | --- | | ||
| 1.0 | Initial version | |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Standard | ||
from unittest.mock import MagicMock, patch | ||
import unittest | ||
|
||
# Third Party | ||
from datasets import Dataset, Features, Value | ||
|
||
# First Party | ||
from src.instructlab.sdg.llmblock import LLMBlock | ||
|
||
|
||
class TestLLMBlockModelPrompt(unittest.TestCase): | ||
def setUp(self): | ||
self.mock_ctx = MagicMock() | ||
self.mock_ctx.model_family = "mixtral" | ||
self.mock_ctx.model_id = "test_model" | ||
self.mock_pipe = MagicMock() | ||
self.config_return_value = { | ||
"system": "{fruit}", | ||
"introduction": "introduction", | ||
"principles": "principles", | ||
"examples": "examples", | ||
"generation": "generation", | ||
} | ||
self.dataset = Dataset.from_dict( | ||
{"fruit": ["apple", "pear", "mango"]}, | ||
features=Features({"fruit": Value("string")}), | ||
) | ||
|
||
@patch("src.instructlab.sdg.block.Block._load_config") | ||
def test_model_prompt_empty_string(self, mock_load_config): | ||
mock_load_config.return_value = self.config_return_value | ||
# Ensure that if an empty model_prompt is not specified, no model prompt is used. | ||
block = LLMBlock( | ||
ctx=self.mock_ctx, | ||
pipe=self.mock_pipe, | ||
block_name="test_block", | ||
config_path="", | ||
output_cols=[], | ||
model_prompt="", | ||
) | ||
prompt = block._format_prompt(self.dataset[0]) | ||
self.assertEqual( | ||
prompt, | ||
"apple\nintroduction\nprinciples\nexamples\ngeneration", | ||
"no model prompt should be used when explicitly set to an empty string", | ||
) | ||
|
||
@patch("src.instructlab.sdg.block.Block._load_config") | ||
def test_model_prompt_none(self, mock_load_config): | ||
mock_load_config.return_value = self.config_return_value | ||
# Ensure that if a custom model_prompt is not specified, it defaults to setting it to | ||
# something based on the model family (i.e. mixtral). | ||
block = LLMBlock( | ||
ctx=self.mock_ctx, | ||
pipe=self.mock_pipe, | ||
block_name="test_block", | ||
config_path="", | ||
output_cols=[], | ||
model_prompt=None, # Or simply omit model_prompt as it defaults to None | ||
) | ||
prompt = block._format_prompt(self.dataset[1]) | ||
self.assertEqual( | ||
prompt, | ||
"<s> [INST] pear\nintroduction\nprinciples\nexamples\ngeneration [/INST]", | ||
"model_prompt based on model_family should be used set to None", | ||
) | ||
|
||
@patch("src.instructlab.sdg.block.Block._load_config") | ||
def test_model_prompt_none(self, mock_load_config): | ||
mock_load_config.return_value = self.config_return_value | ||
# Ensure that if a custom model_prompt is specified, it is used correctly | ||
block = LLMBlock( | ||
ctx=self.mock_ctx, | ||
pipe=self.mock_pipe, | ||
block_name="test_block", | ||
config_path="", | ||
output_cols=[], | ||
model_prompt="FOO {prompt} BAR", | ||
) | ||
prompt = block._format_prompt(self.dataset[1]) | ||
self.assertEqual( | ||
prompt, | ||
"FOO pear\nintroduction\nprinciples\nexamples\ngeneration BAR", | ||
"model_prompt should be a non-empty string when set to None", | ||
) |
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.
nit:
double "/"'s in path name
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.
oops