kineto icon indicating copy to clipboard operation
kineto copied to clipboard

Windows Bug: json.decoder.JSONDecodeError: Invalid \escape

Open IDGallagher opened this issue 2 years ago • 4 comments

I'm running torch-tb-profiler 0.4.1 on windows and getting the same issue as in #336

Invalid \escape when decoding the JSON. The fix specified in #336 still works although the line is now 131:

Change line 131 in '\path_to_python_installation\Lib\site-packages\torch_tb_profiler\profiler\data.py' to trace_json = json.loads(data.replace(b"\", b"\\"), strict=False)

IDGallagher avatar Apr 15 '23 21:04 IDGallagher

@davidberard98 has added a fix for this issue in https://github.com/pytorch/kineto/pull/754. @IDGallagher , could you please validate if that fixes your issue?

aaronenyeshi avatar May 09 '23 16:05 aaronenyeshi

May need to wait for next release to pick up the fixes.

aaronenyeshi avatar Jun 23 '23 14:06 aaronenyeshi

Can you please try torch-tb-profiler 0.4.3 package?

aaronenyeshi avatar Oct 06 '23 15:10 aaronenyeshi

I think this issue still persists with torch-tb-profiler 0.4.3. I add this line: str_data = str_data.replace("\\", "\\\\") and it works.

          try:
              trace_json = json.loads(data, strict=False)
          except JSONDecodeError:
              with sysio.StringIO() as fout:
                  str_data = data.decode('utf-8')
                  str_data = str_data.replace("\\", "\\\\")
                  # only replace the N/A without surrounding double quote
                  fout.write(re.sub(r'(?<!")N/A(?!")', "\"N/A\"", str_data))
                  trace_json = json.loads(fout.getvalue())
                  logger.warning('Get JSONDecodeError: %s, Re-encode it to temp file' % e.msg)
                  json_reencode = True

diaoenmao avatar Jan 09 '24 04:01 diaoenmao