-
Notifications
You must be signed in to change notification settings - Fork 68
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
Validate context length for generation and validation #33
Merged
sfc-gh-jhilgart
merged 6 commits into
main
from
jhilgart/check-context-length-for-generation-and-validation
May 9, 2024
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4e81047
Validate context length for generation and validation
sfc-gh-jhilgart 9cb9419
fix test
sfc-gh-jhilgart 9c60980
instr token buffer
sfc-gh-jhilgart 07684bd
lint
sfc-gh-jhilgart 360b249
feedback
sfc-gh-jhilgart 20f73e9
black
sfc-gh-jhilgart 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,11 @@ | ||
_MODEL_CONTEXT_LENGTH = 7000 # We use 7k so that we can reserve 1k for response tokens. | ||
sfc-gh-jhilgart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def validate_context_length(yaml_str: str) -> None: | ||
# Pass in the str version of the semantic context yaml. | ||
# This isn't exactly how many tokens the model will be, but should roughly be correct. | ||
CHARS_PER_TOKEN = 4 # as per https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them | ||
if len(yaml_str) // CHARS_PER_TOKEN > _MODEL_CONTEXT_LENGTH: | ||
raise ValueError( | ||
f"Your semantic model is too large. Passed size is {len(yaml_str)} characters. We need you to remove {((len(yaml_str) // CHARS_PER_TOKEN)-_MODEL_CONTEXT_LENGTH ) *CHARS_PER_TOKEN } characters in your semantic model. Please check: \n (1) If you have long descriptions that can be truncated. \n (2) If you can remove some columns that are not used within your tables. \n (3) If you have extra tables you do not need. \n (4) If you can remove sample values." | ||
) |
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
Oops, something went wrong.
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.
Shouldn't we account for instruction tokens in the prompt?
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.
This is pretty loose as is. Instruction tokens, even for llama3, are only ~20 tokens.
I can add an additional buffer here though!