Repository navigation
model generate wrong text like � when utf8 decode error in some languages like chinese - #7069
flycloud-hz wants to merge 1 commit into
Conversation
WalkthroughAdds a guard in CompletionOutput.text_diff to return an empty string when the computed diff ends with the Unicode replacement character '�', skipping _last_text updates; otherwise existing behavior is unchanged. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Caller
participant CO as CompletionOutput
participant S as Internal State (_last_text)
C->>CO: text_diff(new_text)
CO->>CO: compute diff = new_text - S._last_text
alt diff ends with '�' (guard)
note right of CO: Suppress stray replacement char
CO-->>C: return ""
CO-xS: do not update _last_text
else No trailing '�'
CO->>S: update _last_text
CO-->>C: return diff
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
1eb0647 to
484311e
Compare
…eral tokens combine one character Signed-off-by: flycloud_hz <[email protected]>
484311e to
1ece984
Compare
|
@coderabbitai review |
🧩 Analysis chain🏁 Script executed: Length of output: 280651 🏁 Script executed: Length of output: 816 🏁 Script executed: Length of output: 2608 🏁 Script executed: Length of output: 4383 🏁 Script executed: Length of output: 5847 🏁 Script executed: Length of output: 2581 @flycloud-hz, I'll help you implement a fix for the UTF-8 decode error issue. Based on the PR description and my analysis of the codebase, the problem occurs when decoding tokens that form multi-byte UTF-8 characters (like Chinese characters) one at a time. Here's the fix that should be applied: Fix for UTF-8 Decode Errors1. Update the tokenizer decode method (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
tensorrt_llm/executor.py (2)
125-131: Make tail handling more robust and avoid literal '�'; also stream the completed portion instead of dropping everything.Returning an empty string when the diff ends with the replacement character works but:
- It suppresses already-valid text that precedes the trailing U+FFFD.
- It hardcodes a literal '�' which is brittle across file encodings and editors.
- It doesn’t handle multiple trailing U+FFFD characters.
Refine the logic to rstrip any trailing U+FFFD, emit the completed portion, and advance
_last_textaccordingly. Use the explicit code point to avoid encoding ambiguities.@property def text_diff(self) -> str: - diff = self.text[len(self._last_text):] - if diff.endswith('�'): - return '' - self._last_text = self.text - return diff + diff = self.text[len(self._last_text):] + # Hold back any trailing Unicode replacement chars (U+FFFD) that usually + # indicate an incomplete UTF-8 sequence in streaming scenarios. + if diff and diff[-1] == "\uFFFD": + emit = diff.rstrip("\uFFFD") + if not emit: + return "" + # Stream only the completed portion now; keep the remainder for the next step. + self._last_text += emit + return emit + self._last_text = self.text + return diff
125-131: Add minimal tests for CJK/emoji multi-byte boundaries in streaming.To prevent regressions, add tests that simulate:
- diff ending with U+FFFD (should defer emission and not advance
_last_text);- subsequent completion where the replacement char disappears (should emit the withheld text);
- multiple trailing U+FFFD characters;
- legitimate U+FFFD inside the diff (not at the tail) which should still be emitted.
I can help draft these tests against CompletionOutput.text_diff if you’d like.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
tensorrt_llm/executor.py(1 hunks)
🔇 Additional comments (1)
tensorrt_llm/executor.py (1)
125-131: Discard the suggestion to adjust Python-level decode error handling• Searched for all
decode(calls and expliciterrors=parameters across the repository; found no instances oferrors='replace'(default Pythonbytes.decode()uses strict error handling) nor any other misuse of theerrorsargument in streaming paths.
• All text produced byself.textis generated via the tokenizer’sdecode(token_ids), which maps token IDs to Unicode strings without invoking a replacement-mode UTF-8 decoder.
• The U+FFFD guard intext_diffis specific to masking incomplete or invalid byte sequences emitted by the C++/TensorRT plugin’s streaming interface, not a symptom of Python decode calls.The original advice to “address root cause at decode time by switching to incremental UTF-8 or
errors='ignore'” does not apply, since no Python decode calls useerrors='replace'. Retain the existingtext_diffguard for the plugin’s streaming output.Likely an incorrect or invalid review comment.
This change is better,Thanks! |
The stop-criteria helpers moved out of TorchSampler into module-level
functions in sampler_features.py, but spec_sampler_base.py still reached for
the old classmethod:
if TorchSampler._handle_stop_criteria(
req, new_token, max_seq_len=self.max_seq_len, beam_idx=beam_idx
):
which now raises
AttributeError: type object 'TorchSampler' has no attribute
'_handle_stop_criteria'
on every one-model speculative-decoding step. Caught by CI on NVIDIA#17890
(L0_Test-x86_64-Single-GPU NVIDIA#7069, test_spec_dec_stats_pairing).
Import the module-level handle_stop_criteria instead; the signature is
unchanged, so the call site only loses the class qualifier. TorchSampler is
still imported here for TorchSampler.Args.
This was missed because the caller reaches the helper as a class attribute
rather than importing it by name, so neither the package-level import sweep
nor a grep for the symbol as an imported name found it.
Signed-off-by: ZhaoyangWang <[email protected]>
The stop-criteria helpers moved out of TorchSampler into module-level
functions in sampler_features.py, but spec_sampler_base.py still reached for
the old classmethod:
if TorchSampler._handle_stop_criteria(
req, new_token, max_seq_len=self.max_seq_len, beam_idx=beam_idx
):
which now raises
AttributeError: type object 'TorchSampler' has no attribute
'_handle_stop_criteria'
on every one-model speculative-decoding step. Caught by CI on NVIDIA#17890
(L0_Test-x86_64-Single-GPU NVIDIA#7069, test_spec_dec_stats_pairing).
Import the module-level handle_stop_criteria instead; the signature is
unchanged, so the call site only loses the class qualifier. TorchSampler is
still imported here for TorchSampler.Args.
This was missed because the caller reaches the helper as a class attribute
rather than importing it by name, so neither the package-level import sweep
nor a grep for the symbol as an imported name found it.
Signed-off-by: ZhaoyangWang <[email protected]>
In some situation, several tokens combine one chinese character. When you have only one token to decode and error occurs.
So we could skip decoding errored character and wait the remaining tokens come.
Summary by CodeRabbit
Description
Test Coverage
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
Details
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.