欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > 【Pytorch】解决pytorch profiler导出的json文件在浏览器中无法打开的问题

【Pytorch】解决pytorch profiler导出的json文件在浏览器中无法打开的问题

2024/10/23 23:26:08 来源:https://blog.csdn.net/weixin_45207619/article/details/140888696  浏览:    关键词:【Pytorch】解决pytorch profiler导出的json文件在浏览器中无法打开的问题

笔者在服务器上进行pytorch profiler的实验,导出的json文件下载到本地之后通过edge://tracing打开时报错(edge和chrome使用的是同一套内核,笔者也测试了在chrome下同样报错):

SyntaxError: Unexpected token 'i', ..." per SM": inf,"... is not valid JSONat JSON.parse (<anonymous>)at new TraceEventImporter (edge://tracing/tracing.js:6342:19)at Import.createImporter_ (edge://tracing/tracing.js:2033:8)at edge://tracing/tracing.js:2025:167at Task.run (edge://tracing/tracing.js:2948:95)at runAnother (edge://tracing/tracing.js:2951:371)at runTask (edge://tracing/tracing.js:2927:57)at processIdleWork (edge://tracing/tracing.js:2932:116)at window.requestIdleCallback.timeout (edge://tracing/tracing.js:2925:81) pytorch profile

通过vscode打开之后发现有很多红色的报错信息,看到是inf,和报错信息也吻合了。
GPT给出的脚本,笔者进行了微调:

import json# 读取原始 JSON
with open('trace.json', 'r') as f:raw_data = f.read()# 替换不兼容的值
raw_data = raw_data.replace('inf', '1e308')  # 替换 Infinity
raw_data = raw_data.replace('nan', 'null')  # 替换 NaN# 解析为字典
data = json.loads(raw_data)# 写回 JSON 文件
with open('trace_fixed.json', 'w') as f:json.dump(data, f, indent=4)print("修复后的 JSON 已保存为 trace_fixed.json")

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com