-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix log parsing undefined variable and duplicate sequence id errors (#…
…1809) * Fixes two related bugs which occur when running the `log_parsing` example with unexpected data. * Fix error in `LogParsingPostProcessingStage::__get_label_dicts` where there is a possibility that the `new_label` and `new_confidence` variables are undefined. * Fix error where the `tokenize_text_series` method can return a sequence_ids list with duplicate ids when a text series is passed in and one of the values has a length longer than `seq_len` and `truncation=False`, this prevents a down-stream error in the inference stage ``` RuntimeError: Inconsistent ID column. Last element in 'seq_ids' tensor, [1], must not extend beyond last message, [0] ``` Not sure if this is the best place to catch this error. Closes #1765 ## By Submitting this PR I confirm: - I am familiar with the [Contributing Guidelines](https://github.com/nv-morpheus/Morpheus/blob/main/docs/source/developer_guide/contributing.md). - When the PR is ready for review, new or existing tests cover these changes. - When the PR is ready for review, the documentation is up to date with these changes. Authors: - David Gardner (https://github.com/dagardner-nv) Approvers: - Michael Demoret (https://github.com/mdemoret-nv) URL: #1809
- Loading branch information
1 parent
79ed546
commit a527ee7
Showing
7 changed files
with
164 additions
and
20 deletions.
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
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
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,53 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
# | ||
# 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. | ||
|
||
import string | ||
|
||
import pytest | ||
|
||
import cudf | ||
|
||
from morpheus.utils.cudf_subword_helper import tokenize_text_series | ||
|
||
|
||
@pytest.mark.parametrize("seq_length", [10, 256, 1024]) | ||
@pytest.mark.parametrize("do_lower_case", [False, True]) | ||
@pytest.mark.parametrize("add_special_tokens", [False, True]) | ||
def test_needs_trunc_error(bert_cased_hash: str, seq_length: int, do_lower_case: bool, add_special_tokens: bool): | ||
""" | ||
Feeding the subword tokenizer with a string that is too long should raise an error rather than | ||
a duplicate in the id list | ||
""" | ||
|
||
short_string = string.ascii_lowercase[0:seq_length - 1] | ||
|
||
long_string = list(string.ascii_lowercase) | ||
while len(long_string) <= seq_length: | ||
long_string.extend(string.ascii_lowercase) | ||
|
||
long_string = "".join(long_string) | ||
|
||
series = cudf.Series([short_string, long_string]) | ||
|
||
# Infer the value of stride the same way that the PreprocessNLPStage does | ||
stride = (seq_length // 2) + (seq_length // 4) | ||
|
||
with pytest.raises(ValueError): | ||
tokenize_text_series(vocab_hash_file=bert_cased_hash, | ||
do_lower_case=do_lower_case, | ||
text_ser=series, | ||
seq_len=seq_length, | ||
truncation=False, | ||
stride=stride, | ||
add_special_tokens=add_special_tokens) |