generated from caikit/caikit-template
-
Notifications
You must be signed in to change notification settings - Fork 55
✨ Text generation input inference data models #151
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
tharapalanivel
wants to merge
2
commits into
caikit:main
Choose a base branch
from
tharapalanivel:nested_inf_data_models
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # Copyright The Caikit Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Local | ||
| from caikit_nlp.data_model import ( | ||
| DecodingParameters, | ||
| SamplingParameters, | ||
| StoppingCriteria, | ||
| ) | ||
|
|
||
| ## Setup ######################################################################### | ||
|
|
||
| dummy_exponential_decay_length_penalty = ( | ||
| DecodingParameters.ExponentialDecayLengthPenalty(start_index=1, decay_factor=0.95) | ||
| ) | ||
| dummy_sampling_parameters = DecodingParameters( | ||
| repetition_penalty=1.2, | ||
| exponential_decay_length_penalty=dummy_exponential_decay_length_penalty, | ||
| ) | ||
|
|
||
| dummy_sampling_parameters = SamplingParameters( | ||
| temperature=0.5, top_k=0, top_p=0, typical_p=0.2, seed=42 | ||
| ) | ||
|
|
||
| dummy_stopping_criteria = StoppingCriteria( | ||
| max_new_tokens=200, min_new_tokens=50, time_limit_millis=0, stop_sequences=["Test"] | ||
| ) | ||
|
|
||
| ## Tests ######################################################################## | ||
|
|
||
| ### Decoding Parameters | ||
| def test_sampling_parameters_all_fields_accessible(): | ||
| assert dummy_sampling_parameters.repetition_penalty == 1.2 | ||
| assert dummy_sampling_parameters.exponential_decay_length_penalty.start_index == 1 | ||
| assert ( | ||
| dummy_sampling_parameters.exponential_decay_length_penalty.decay_factor == 0.95 | ||
| ) | ||
|
|
||
|
|
||
| def test_sampling_parameters_from_proto_and_back(): | ||
| new = DecodingParameters.from_proto(dummy_sampling_parameters.to_proto()) | ||
| assert new.repetition_penalty == 1.2 | ||
| assert new.exponential_decay_length_penalty.start_index == 1 | ||
| assert new.exponential_decay_length_penalty.decay_factor == 0.95 | ||
|
|
||
|
|
||
| def test_sampling_parameters_from_json_and_back(): | ||
| new = DecodingParameters.from_json(dummy_sampling_parameters.to_json()) | ||
| assert new.repetition_penalty == 1.2 | ||
| assert new.exponential_decay_length_penalty.start_index == 1 | ||
| assert new.exponential_decay_length_penalty.decay_factor == 0.95 | ||
|
|
||
|
|
||
| ### Sampling Parameters | ||
| def test_sampling_parameters_all_fields_accessible(): | ||
| assert dummy_sampling_parameters.temperature == 0.5 | ||
| assert dummy_sampling_parameters.top_k == 0 | ||
| assert dummy_sampling_parameters.top_p == 0 | ||
| assert dummy_sampling_parameters.typical_p == 0.2 | ||
| assert dummy_sampling_parameters.seed == 42 | ||
|
|
||
|
|
||
| def test_sampling_parameters_from_proto_and_back(): | ||
| new = SamplingParameters.from_proto(dummy_sampling_parameters.to_proto()) | ||
| assert new.temperature == 0.5 | ||
| assert new.top_k == 0 | ||
| assert new.top_p == 0 | ||
| assert new.typical_p == 0.2 | ||
| assert new.seed == 42 | ||
|
|
||
|
|
||
| def test_sampling_parameters_from_json_and_back(): | ||
| new = SamplingParameters.from_json(dummy_sampling_parameters.to_json()) | ||
| assert new.temperature == 0.5 | ||
| assert new.top_k == 0 | ||
| assert new.top_p == 0 | ||
| assert new.typical_p == 0.2 | ||
| assert new.seed == 42 | ||
|
|
||
|
|
||
| ### Stopping Criteria | ||
| def test_stopping_criteria_all_fields_accessible(): | ||
| assert dummy_stopping_criteria.max_new_tokens == 200 | ||
| assert dummy_stopping_criteria.min_new_tokens == 50 | ||
| assert dummy_stopping_criteria.time_limit_millis == 0 | ||
| assert dummy_stopping_criteria.stop_sequences == ["Test"] | ||
|
|
||
|
|
||
| def test_stopping_criteria_from_proto_and_back(): | ||
| new = StoppingCriteria.from_proto(dummy_stopping_criteria.to_proto()) | ||
| assert new.max_new_tokens == 200 | ||
| assert new.min_new_tokens == 50 | ||
| assert new.time_limit_millis == 0 | ||
| assert new.stop_sequences == ["Test"] | ||
|
|
||
|
|
||
| def test_stopping_criteria_from_json_and_back(): | ||
| new = StoppingCriteria.from_json(dummy_stopping_criteria.to_json()) | ||
| assert new.max_new_tokens == 200 | ||
| assert new.min_new_tokens == 50 | ||
| assert new.time_limit_millis == 0 | ||
| assert new.stop_sequences == ["Test"] |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
It might be a good idea to set some default! TGIS defaults are here.
Most of the time this doesn't matter, because 0 temperature (in the IBM fork) indicates greedy decoding, so
top_k,top_p,typical_p, etc won't be used, as they're sampling only.TGI doesn't use temperature 0 as a toggle though, so it would be also be nice in case those APIs are ever more unified - currently there are some small divergences with stuff like prompt IDs. I'm not sure if our raw generation modules are compatible with it or not
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.
Haven't seen us setting defaults on the data models themselves, only in the inference methods. I don't really have a strong opinion on this, trying to understand if that is the general direction
caikitis moving inThere 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.
I think even if we set defaults on the DM, they won't propagate to proto, so the default here would be guided by the
.runfunction themselves.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.
Good point - my main concern with leaving it up to run is that it's easy for defaults to get out of sync if we have multiple modules relying on them.
I guess an alternate is to either have a building for getting these objects with their default values that make sense, or to have consts be passed to the run function 🤔 is the intent with this type to have a parameter that is this DM object type, or to take primitives and build this object in the requests?