Skip to content

Commit

Permalink
Workaround: Remove non-utf at start of triton response string (#501)
Browse files Browse the repository at this point in the history
* Workaround: Remove non-utf at start of triton response string

* Fix formatting failures

---------

Co-authored-by: Elias Bermudez <[email protected]>
  • Loading branch information
2 people authored and mc-nv committed Mar 13, 2024
1 parent 9c4775d commit 6d8e3f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/c++/perf_analyzer/genai-pa/genai_pa/llm_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,24 @@ def _parse_requests(self, requests: dict) -> LLMMetrics:
num_generated_tokens,
)

def _remove_leading_invalid_chars(self, text: str):
for i, char in enumerate(text):
# There will be 3 or 4 chars
# (but sometimes the first char looks valid, so don't stop until we've seen at least 3)
if char.isprintable() and i > 2:
break

return text[i:]

def _preprocess_response(
self, res_timestamps: list[int], res_outputs: list[dict[str, str]]
) -> None:
# FIXME -- remove this triton code once it is properly fixed in PA
# (PA/triton will add junk to the start of the BYTES array. Remove it here)
if self._service_kind == "triton":
for d in res_outputs:
d["text_output"] = self._remove_leading_invalid_chars(d["text_output"])

"""Helper function to preprocess responses of a request."""
if self._service_kind == "openai":
openai_final_response = res_outputs[-1]["response"]
Expand Down
2 changes: 1 addition & 1 deletion src/c++/perf_analyzer/genai-pa/genai_pa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def remove_sse_prefix(msg: str) -> str:


def load_json(filename: str):
with open(filename) as f:
with open(filename, encoding="utf-8", errors="ignore") as f:
return json.load(f)


Expand Down

0 comments on commit 6d8e3f4

Please sign in to comment.