question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Trace output for `BYTES` has invalid JSON encoding

See original GitHub issue

Description The trace file being written to disc doesn’t not contain validate json due to the addition quotes being include in the output of BYTES (string) inputs. See below the text "male" is being output with ""make"".

Triton Information What version of Triton are you using?

  • nvcr.io/nvidia/tritonserver:22.05-pyt-python-py3

Are you using the Triton container or did you build it yourself?

  • triton container

To Reproduce Steps to reproduce the behavior.

Following is the example input payload that I sent to the model:

payload = {
    "inputs": [
        {"name": "Sex", "shape": [1], "datatype": "BYTES", "data": ["male"] },
        {"name": "Age", "shape": [1], "datatype": "FP32", "data": [34.5] },
    ]
}

And a sample from the trace output.

{"id":1,"activity":"TENSOR_QUEUE_INPUT","tensor":{"name":"Sex","data":""male"","shape":"1","dtype":"BYTES"},
{"name":"Age","data":"34.5","shape":"1","dtype":"FP32"}

I am using an ensemble model with the input/outputs as show below:

name: "titanic_ensemble"
platform: "ensemble"
max_batch_size: 0 # Dynamic batch not supported
input [
  {
    name: "Pclass"
    data_type: TYPE_STRING
    dims: [ 1 ]
  },
  {
    name: "Sex"
    data_type: TYPE_STRING
    dims: [ 1 ]
  },
  {
    name: "Age"
    data_type: TYPE_FP32
    dims: [ 1 ]
  },
  {
    name: "SibSp"
    data_type: TYPE_FP32
    dims: [ 1 ]
  },
  {
    name: "Parch"
    data_type: TYPE_FP32
    dims: [ 1 ]
  },
  {
    name: "Fare"
    data_type: TYPE_FP32
    dims: [ 1 ]
  },
  {
    name: "Embarked"
    data_type: TYPE_STRING
    dims: [ 1 ]
  }
]
output [
  {
    name: "Survived_predictions"
    data_type: TYPE_STRING
    dims: [ 1 ]
  },
  {
    name: "Survived_probabilities"
    data_type: TYPE_FP32
    dims: [ 1, 3 ]
  }
]
...

Expected behavior I would expect to be able to parse the json file, but attempting to pipe to JQ fails eg:

cat trace.json | jq

It seems that additional quotes are added for the BYTES type which is in addition to the quote being add a the start and end of the data value.

A potential fix could be to not quote all outputs, which would mean the 34.5 value is returned as a floating point in json that matches the input. Otherwise, quotes in strings should get escaped.

I notice that each file is an actual json array. I wonder if tracer could be simpler and more scalable to just create a JSON lines output, so that you append to the buffer and can flush without having to start and end the trace file with an array [ ] ?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kthuicommented, Jul 30, 2022

This fix is scheduled for 22.08 CC @GuanLuo @nv-kmcgill53

0reactions
brightsparccommented, Aug 1, 2022

I’ve found one further bug in the trace_summary implement and proposed a fix @kthui

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - How do I automatically fix an invalid JSON string?
How can I fix it automatically in Python? This is an encoding issue, not a JSON issue. Can you isolate this to a...
Read more >
proto_tree_add_string allows adding non UTF-8 strings, which ...
Summary Wireshark internally expects strings to be valid UTF-8 regardless of the original encoding. proto_tree_add_item() requires an ...
Read more >
UTF-8 - Wikipedia
UTF-8 is a variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from Unicode (or ...
Read more >
bugs - Who is to blame: parsing UTF8 encoded JSON ...
So the problem occurs because of double decoding. Workaround? Use BodyBytes (see below) or URLExecute . It should be easier to understand this ......
Read more >
cPanel fork of JSON::XS, fast and correct serializing - MetaCPAN
With the binary flag enabled decode the perl utf8 encoded string to the original byte encoding and encode this with \xNN escapes. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found