Use first bad_words as extra parameters, and implement min-p - #1536
Closed
pathorn wants to merge 2 commits into
Closed
Use first bad_words as extra parameters, and implement min-p#1536pathorn wants to merge 2 commits into
pathorn wants to merge 2 commits into
Conversation
Contributor
Author
|
Here is some example BLS code for adding the min_p value into the bad_words list in the way this PR expects: numpy_tensor = preproc_output_tensor.as_numpy()
if trtllm_tensor_name == "bad_words_list":
bad_words_data, bad_words_offsets = numpy_tensor[0]
opt = np.get_printoptions()
np.set_printoptions(threshold=np.inf)
pprint(numpy_tensor)
min_p = 0.0
if "min_p" in bls_input_tensors_map:
minptensor = bls_input_tensors_map["min_p"].as_numpy()
pprint(minptensor)
min_p = minptensor[0,0]
min_p_int ,= struct.unpack('i', struct.pack('f', min_p))
extra_data = np.array([min_p_int], dtype=np.int32)
if bad_words_offsets[0] == -1:
# Special case: if no bad_words are passed, numpy_tensor will be [[[0], [-1]]]
# In this case, we don't want to prepend [0] because that would add a bad word offset where there otherwise was none.
bad_words_data = extra_data
bad_words_offsets = np.array([-1], dtype=np.int32)
else:
# Prepend min_p words.
bad_words_data = np.concatenate((extra_data, bad_words_data), axis=0)
# The offsets array is padded with -1, so we first add one to make the padding all zeros, then trim_zeros and subtract one.
bad_words_offsets = np.trim_zeros(bad_words_offsets + 1) - 1
# Then, we prepend an extra 0 element to account for an extra bad_word being added.
bad_words_offsets = np.concatenate((np.array([0], dtype=np.int32), bad_words_offsets), axis=0)
# Then, we offset the indices by the length of the newly added data.
bad_words_offsets = bad_words_offsets + len(extra_data)
# Finally, we pad this array to make it the same length as bad_words_data:
bad_words_offsets = np.concatenate((bad_words_offsets, np.array([-1] * (len(bad_words_data) - len(bad_words_offsets)), dtype=np.int32)), axis=0)
numpy_tensor = np.array([[bad_words_data, bad_words_offsets]], dtype=np.int32)
print("Final:")
pprint(numpy_tensor)
np.set_printoptions(**opt)
trtllm_input_tensors.append(
pb_utils.Tensor(trtllm_tensor_name,
numpy_tensor)) |
pathorn
force-pushed
the
minp_via_badwords_apr30
branch
from
May 3, 2024 22:40
7e1acc9 to
3731f5b
Compare
Collaborator
|
Hi Pathorn Thanks for your interest to submit the MR into TRT-LLM. The current process of merging community MR into TRT-LLM is:
Pls let me know whether the above process makes sense to you. June |
pathorn
force-pushed
the
minp_via_badwords_apr30
branch
from
May 29, 2024 10:31
3731f5b to
3d7d658
Compare
pathorn
force-pushed
the
minp_via_badwords_apr30
branch
from
June 5, 2024 17:01
3d7d658 to
0481a36
Compare
pathorn
force-pushed
the
minp_via_badwords_apr30
branch
from
June 25, 2024 14:04
0481a36 to
f4c8e1c
Compare
pathorn
force-pushed
the
minp_via_badwords_apr30
branch
from
September 25, 2024 00:13
f4c8e1c to
a248ba1
Compare
pathorn
force-pushed
the
minp_via_badwords_apr30
branch
2 times, most recently
from
October 9, 2024 07:05
d1f2263 to
55db1b6
Compare
pathorn
force-pushed
the
minp_via_badwords_apr30
branch
from
October 16, 2024 22:59
55db1b6 to
6b54714
Compare
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
An approach for implementing #1154
The user-facing classes in BatchManager and
tensorrt_llm::executor::SamplingConfigare not open source (the constructor implementation exists in .a files and will segfault if the class is modified), so we hacked it by using the integers in the first bad_words for extra parameters.In this case, we're using the first integer reinterpreted as a float, to represent min_p (the default value is 0.0 which matches the 0 padding in bad_words).
I implemented the min-p by piggybacking on the existing logprobs calculation in cuda, so it should have no additional performance overhead beyond the logprobs calculation.