From 605b95c193501ac727c0a60613775637835d04cc Mon Sep 17 00:00:00 2001 From: sunchao <1299792067@qq.com> Date: Fri, 15 Aug 2025 14:25:47 +0800 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0TensorBoard?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E5=8F=AF=E8=A7=86=E5=8C=96=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tb_graph_ascend/monvis_plugin/LICENSE | 201 ++++++++++++ .../tb_graph_ascend/monvis_plugin/README.md | 112 +++++++ .../tb_graph_ascend/monvis_plugin/__init__.py | 15 + .../tb_graph_ascend/monvis_plugin/fe/.babelrc | 3 + .../monvis_plugin/fe/.prettierrc | 13 + .../monvis_plugin/fe/package.json | 49 +++ .../monvis_plugin/fe/public/index.html | 10 + .../fe/src/common/SelectWithLabel/index.less | 59 ++++ .../fe/src/common/SelectWithLabel/index.tsx | 37 +++ .../fe/src/common/constant/index.ts | 57 ++++ .../fe/src/common/type/index.d.ts | 40 +++ .../fe/src/controller/index.less | 34 ++ .../monvis_plugin/fe/src/controller/index.tsx | 216 +++++++++++++ .../fe/src/controller/type/index.d.ts | 39 +++ .../fe/src/controller/useController.ts | 59 ++++ .../fe/src/graph/components/HeatMap/index.tsx | 97 ++++++ .../graph/components/HeatMap/useHeatMap.ts | 297 ++++++++++++++++++ .../src/graph/components/LineChart/index.tsx | 140 +++++++++ .../fe/src/graph/components/type/index.d.ts | 32 ++ .../monvis_plugin/fe/src/graph/index.less | 41 +++ .../monvis_plugin/fe/src/graph/index.tsx | 50 +++ .../monvis_plugin/fe/src/index.tsx | 26 ++ .../monvis_plugin/fe/src/main/index.less | 26 ++ .../monvis_plugin/fe/src/main/index.tsx | 60 ++++ .../monvis_plugin/fe/src/main/type/index.d.ts | 26 ++ .../monvis_plugin/fe/src/store/index.ts | 39 +++ .../monvis_plugin/fe/src/utils/index.ts | 27 ++ .../monvis_plugin/fe/src/utils/request.ts | 91 ++++++ .../monvis_plugin/fe/tsconfig.json | 40 +++ .../monvis_plugin/fe/webpack.config.js | 81 +++++ .../monvis_plugin/fe/webpack.dev.js | 160 ++++++++++ .../monvis_plugin/server/__init__.py | 15 + .../monvis_plugin/server/app.py | 57 ++++ .../server/controllers/__init__.py | 15 + .../server/controllers/monvis_controller.py | 103 ++++++ .../monvis_plugin/server/database/__init__.py | 15 + .../server/database/db_connection.py | 40 +++ .../server/repositories/__init__.py | 15 + .../server/repositories/monvis_repo.py | 116 +++++++ .../monvis_plugin/server/services/__init__.py | 15 + .../server/services/monvis_service.py | 196 ++++++++++++ .../monvis_plugin/server/static/__init__.py | 15 + .../monvis_plugin/server/static/index.js | 19 ++ 43 files changed, 2798 insertions(+) create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/LICENSE create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/README.md create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/__init__.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/.babelrc create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/.prettierrc create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/package.json create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/public/index.html create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/SelectWithLabel/index.less create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/SelectWithLabel/index.tsx create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/constant/index.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/type/index.d.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/index.less create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/index.tsx create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/type/index.d.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/useController.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/HeatMap/index.tsx create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/HeatMap/useHeatMap.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/LineChart/index.tsx create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/type/index.d.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/index.less create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/index.tsx create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/index.tsx create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/index.less create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/index.tsx create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/type/index.d.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/store/index.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/utils/index.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/utils/request.ts create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/tsconfig.json create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/webpack.config.js create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/webpack.dev.js create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/__init__.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/app.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/controllers/__init__.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/controllers/monvis_controller.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/database/__init__.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/database/db_connection.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/repositories/__init__.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/repositories/monvis_repo.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/services/__init__.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/services/monvis_service.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/static/__init__.py create mode 100644 plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/server/static/index.js diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/LICENSE b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/README.md b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/README.md new file mode 100644 index 000000000..9e3e96938 --- /dev/null +++ b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/README.md @@ -0,0 +1,112 @@ +# TensorBoard 监控可视化插件 +一个用于可视化模型监控指标的TensorBoard插件,支持热力图和趋势图分析。项目文件中提供将CSV格式的监控数据导入SQLite数据库的脚本,然后使用可插件生成交互式可视化界面。 + +## 核心功能 +- **数据导入DB**:将monitor工具CSV文件转换为SQLite格式 +- **交互式热力图**:支持跨维度(训练步数、rank、模块/参数)指标统计量可视化 +- **趋势分析**:查看选定维度的指标变化趋势 + +## 使用流程 +```mermaid + +graph LR + F[安装插件包] --> A + + subgraph 数据准备 + A[monitor输出数据] -->|CSV格式| B(数据转换脚本) + B -->|SQLite格式| C[数据库文件] + end + + subgraph 可视化 + C --> D[TensorBoard] + D --> E[MonVis插件] + end +``` + +## 安装指南 + +1. 克隆项目仓库 +git clone https://gitee.com/jiandaobao/MoniVis.git + +2. 安装插件包: +```bash +cd MoniVis +pip install -e . +``` + +3. 插件安装后会被TensorBoard自动识别 + +## 数据准备 + +### 监控数据路径目录结构要求 +```bash +monitor_output/ +├── date-rank0 +│ ├── grad_reduced_0-100.csv +│ └── param_0-100.csv +└── date-rank1 + ├── grad_reduced_0-100.csv + └── param_0-100.csv +``` + +### 数据转换脚本 +```bash +python3 csv2sqlite.py --db ./db --data ./monitor_output --workers 4 +``` + +### 命令行参数 + +| 参数名称 | 必选 | 数据类型 | 默认值 | 描述 | +| ------------- | ---- | -------- | ------ | ---------------------------------------------- | +| `--db` | 是 | string | 无 | SQLite数据库文件存储目录 | +| `--data` | 是 | string | 无 | 监控数据目录路径 | +| `--workers` | 否 | int | 1 | 并行处理的工作线程数 | +| `--partition` | 否 | int | 50 | Step分区大小(控制每个SQLite表存储的step范围) | + +#### 输入数据要求 +| 文件命名格式 | 示例 | 说明 | +| ---------------------------- | ---------------------------- | ------------------- | +| `[metric]_[start]-[end].csv` | `grad_reduced_1000-1004.csv` | 必须包含step范围 | +| 文件内容字段 | | | +| `vpp_stage` | 0,1,2... | 模块层级标识 | +| `name` | "encoder.layer1" | 模块名称 | +| `micro_step` | 0 | 微步长(可选,默认0) | +| `step` | 1000 | 训练步数 | +| `[stat]` | norm,mean等 | 统计量字段 | + +## TensorBoard使用 +1. 启动服务: +```bash +tensorboard --logdir=./db --port=6008 +``` + +访问路径: + +浏览器打开 http://localhost:6008 + +选择顶部导航栏的 MonVis 标签页 + + + +## 数据库结构 +| 表名 | 说明 | +| -------------------- | -------------------- | +| `monitoring_targets` | 被监控模块/层信息 | +| `monitoring_metrics` | 可用指标列表 | +| `metric_stats` | 指标的统计量类型 | +| `global_stats` | 全局步数/rank范围 | +| `metric_*_step_*` | 分片存储的指标数据表 | + + +## 项目文件 +```bash +tb_monitor_plugin/ +├── frontend/ # 前端资源 +│ ├── index.js # 可视化主逻辑 +│ └── echarts.js # ECharts库定制版 +├── backend.py # 插件后端核心 +to_SQlite +├── csv2sqlite.py # 数据转换器 +setup.py # 安装配置 +monitor_metrics.db # 自动生成的数据库名 +``` diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/__init__.py b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/__init__.py new file mode 100644 index 000000000..ee2432f47 --- /dev/null +++ b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/__init__.py @@ -0,0 +1,15 @@ +# Copyright (c) 2025, Huawei Technologies. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/.babelrc b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/.babelrc new file mode 100644 index 000000000..18151f1f8 --- /dev/null +++ b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env", "@babel/preset-react"] +} \ No newline at end of file diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/.prettierrc b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/.prettierrc new file mode 100644 index 000000000..e3d2acb00 --- /dev/null +++ b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/.prettierrc @@ -0,0 +1,13 @@ +{ + "parser": "typescript", + "semi": true, + "singleQuote": true, + "jsxSingleQuote": false, + "bracketSpacing": true, + "tabWidth": 2, + "useTabs": false, + "trailingComma": "all", + "proseWrap": "always", + "endOfLine": "lf", + "printWidth": 120 +} diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/package.json b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/package.json new file mode 100644 index 000000000..bcd958160 --- /dev/null +++ b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/package.json @@ -0,0 +1,49 @@ +{ + "name": "fe", + "version": "1.0.0", + "main": "webpack.config.js", + "scripts": { + "dev": "webpack serve --config webpack.dev.js", + "buildWin": "cross-env NODE_ENV=production webpack && copy dist\\index.html ..\\server\\static\\", + "prettier": "prettier --config ./.prettierrc --write ./src/**/*.ts" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "devDependencies": { + "@babel/core": "^7.27.3", + "@babel/preset-env": "^7.27.2", + "@babel/preset-react": "^7.27.1", + "babel-loader": "^10.0.0", + "clean-webpack-plugin": "^4.0.0", + "cross-env": "^7.0.3", + "css-loader": "^7.1.2", + "file-loader": "^6.2.0", + "html-loader": "^5.1.0", + "html-webpack-plugin": "^5.6.3", + "inline-chunk-html-plugin": "^1.1.1", + "less": "^4.3.0", + "less-loader": "^12.3.0", + "mini-css-extract-plugin": "^2.9.2", + "prettier": "^3.5.3", + "style-loader": "^4.0.0", + "ts-loader": "^9.5.2", + "typescript": "^5.8.3", + "webpack": "^5.96.1", + "webpack-cli": "^5.1.4", + "webpack-dev-server": "4.15.1" + }, + "dependencies": { + "ahooks": "^3.8.5", + "antd": "^5.25.3", + "axios": "^1.9.0", + "echarts": "^5.6.0", + "echarts-for-react": "^3.0.2", + "lodash": "^4.17.21", + "react": "^18.0.0", + "react-dom": "^18.0.0", + "use-sync-external-store": "^1.5.0", + "zustand": "^5.0.5" + } +} diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/public/index.html b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/public/index.html new file mode 100644 index 000000000..a0c678cdf --- /dev/null +++ b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/public/index.html @@ -0,0 +1,10 @@ + + + + + Graph + + +
+ + \ No newline at end of file diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/SelectWithLabel/index.less b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/SelectWithLabel/index.less new file mode 100644 index 000000000..a016ed61b --- /dev/null +++ b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/SelectWithLabel/index.less @@ -0,0 +1,59 @@ +/* ------------------------------------------------------------------------- + Copyright (c) 2025, Huawei Technologies. + All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--------------------------------------------------------------------------------------------*/ + +.selector { + padding: 6px 2px; + background-color: white; + box-sizing: border-box; + color: rgb(0, 0, 0); + font-size: 14px; + line-height: 1.5; + margin-bottom: 8px; + + .label { + width: 36%; + cursor: pointer; + margin-bottom: 8px; + color: rgb(68, 68, 68); + font-weight: 400; + + .question-icon { + margin-left: 6px; + font-size: medium; + background-color: white; + cursor: pointer; + } + + &:hover { + color: #0660e7; + } + } + + .select { + width: 100%; + + .ant-select-selector { + border-radius: 0px; + border: 1px solid #161616; + + } + + .ant-select-selection-item { + font-weight: 500; + } + } +} \ No newline at end of file diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/SelectWithLabel/index.tsx b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/SelectWithLabel/index.tsx new file mode 100644 index 000000000..7b9a788af --- /dev/null +++ b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/SelectWithLabel/index.tsx @@ -0,0 +1,37 @@ +/* ------------------------------------------------------------------------- + Copyright (c) 2025, Huawei Technologies. + All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--------------------------------------------------------------------------------------------*/ + +import React from 'react'; +import { Select, Tooltip } from 'antd'; +import { QuestionCircleOutlined } from '@ant-design/icons'; +import './index.less'; +const SelectWithLabel = ({ label, className, text, ...args }: any) => { + return ( +
+ +
+ {label} + + +
+
+ -
- ); -}; - -export default SelectWithLabel; diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/constant/index.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/constant/index.ts deleted file mode 100644 index 52cc0d4cc..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/constant/index.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import { createContext } from 'react'; -import { GlobalContextType } from '../type'; - -export const STEP_DIMENSION = 'step'; -export const RANK_DIMENSION = 'rank'; -export const MODULE_NAME_DIMENSION = 'module_name'; - -export const CONTINUOUS = 'continuous'; -export const PIECEWISE = 'piecewise'; - -export const DIMENSIONS_OPTIONS = [ - { value: STEP_DIMENSION, label: 'Step' }, - { value: RANK_DIMENSION, label: 'Rank' }, - { value: MODULE_NAME_DIMENSION, label: 'Module Name' }, -]; - -export const HEATMAP_TYPE = [ - { value: CONTINUOUS, label: '渐变模式' }, - { value: PIECEWISE, label: '分段模式' }, -]; - -export const DIMENSIONS_AXIS_MAP = { - [STEP_DIMENSION]: { - x: 'Rank', - y: 'Module Name', - }, - [RANK_DIMENSION]: { - x: 'Step', - y: 'Module Name', - }, - [MODULE_NAME_DIMENSION]: { - x: 'Step', - y: 'Rank', - }, -}; - -export const GlobalContext = createContext({ - contextState: [], - setContextState: () => { }, -}); diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/type/index.d.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/type/index.d.ts deleted file mode 100644 index c50cce52d..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/common/type/index.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import type { TrendResponseData } from '../../graph/components/type'; -export interface ContextStateType { - heatMaphData?: Array; - trendData?: TrendResponseData['data']; - metric?: string; - stat?: string; - dimension?: string; - dimensionValue?: string; - heatMapType?: string; - dimX?: string; - dimY?: string; - loadingHeatMap?: boolean; - loadingLineChart?: boolean; - setContextState: (newState: Partial) => void; -} -export type GlobalContextType = { - contextState: ContextStateType; - setContextState: (contextState: ContextStateType) => void; -}; -export type SelectOptionType = { - label: string; - value: string; -}; diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/index.less b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/index.less deleted file mode 100644 index 2d10e24d0..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/index.less +++ /dev/null @@ -1,34 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -.warpper { - background-color: #eeeeee; - height: 100%; -} - -.controller { - padding: 16px 12px; - background-color: white; -} - -.title { - font-size: 16px; - font-weight: 500; - text-align: center; - padding-block: 6px; - background-color: #f1f1f1; -} \ No newline at end of file diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/index.tsx b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/index.tsx deleted file mode 100644 index ee2a7a787..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/index.tsx +++ /dev/null @@ -1,216 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import React, { useEffect, useState, memo } from 'react'; -import { shallow, useShallow } from 'zustand/shallow'; -import { message } from 'antd'; -import { isEmpty } from 'lodash'; -import './index.less'; -import { useGlobalStore } from '../store'; -import { DIMENSIONS_OPTIONS, HEATMAP_TYPE } from '../common/constant'; -import SelectWithLabel from '../common/SelectWithLabel'; -import useController from './useController'; -import type { SelectOptionType } from '../common/type'; -import type { ControllerProps, ValuesResponseType, ValuesRequestParamsType } from './type'; - -const Controller: React.FC = (props: ControllerProps) => { - const { metrics } = props; - const useControllerInstance = useController(); - const { metric, stat, dimension, dimensionValue, heatMapType, setContextState } = useGlobalStore( - useShallow((state) => ({ - metric: state.metric, - stat: state.stat, - dimension: state.dimension, - dimensionValue: state.dimensionValue, - heatMapType: state.heatMapType, - setContextState: state.setContextState, - })), - shallow, - ); - const [metricsMapStats, setMetricsMapStats] = useState>>({}); - const [metricsNameList, setMetricsNameList] = useState([]); - const [statNameList, setStatNameList] = useState([]); - const [dimensionValueList, setDimensionValueList] = useState(); - - useEffect(() => { - if (metrics) { - const metricsMapStats: Record> = {}; - const metricsNameList: Array = []; - metrics.forEach(({ name, stats }) => { - metricsMapStats[name] = stats.map((stat) => { - return { - label: stat, - value: stat, - }; - }); - metricsNameList.push({ label: name, value: name }); - }); - - const selecrMetric = metricsNameList?.[0]?.value; - const statNameList: Array = metricsMapStats[selecrMetric]; - const selectedStat = statNameList?.[0]?.value; - setMetricsMapStats(metricsMapStats); - // 初始化指标 - setMetricsNameList(metricsNameList); - // 初始化统计量 - setStatNameList(statNameList); - setContextState({ metric: selecrMetric, stat: selectedStat }); - // 初始化维度,默认选中step维度 - const params: ValuesRequestParamsType = { - metric: selecrMetric, - stat: selectedStat, - dimension: DIMENSIONS_OPTIONS[0].value, - value: 0, - }; - updateDimensionValueList(params); - } - }, [metrics]); - - useEffect(() => { - if (!metric || !stat || !dimension || !dimensionValue) { - return; - } - const params = { - metric, - stat, - dimension, - value: dimensionValue, - }; - const loadGraphData = async (params) => { - setContextState({ loadingHeatMap: true }); - const result = await useControllerInstance.loadGraphData(params); - setContextState({ loadingHeatMap: false }); - if (result.error) { - message.error(result?.error); - return; - } - setContextState({ - heatMaphData: result?.data, - trendData: { dimensions: [], values: [] }, - dimX: ' ', - dimY: ' ', - }); - }; - loadGraphData(params); - }, [metric, stat, dimension, dimensionValue]); - - const updateDimensionValueList = async (params: ValuesRequestParamsType) => { - const result: ValuesResponseType = await useControllerInstance.loadDimensionValueList(params); - if (result.error) { - message.error(result.error); - return; - } - if (!isEmpty(result)) { - const dimensionValueList = Object.entries(result?.data || {}).map(([key, value]) => { - return { - value: key, - label: value, - }; - }); - setContextState({ - dimension: params.dimension, - dimensionValue: dimensionValueList?.[0]?.value, - }); - setDimensionValueList(dimensionValueList); - } - }; - - // 指标选择 - const onSelectMetricChange = (value: string) => { - const statNameList = metricsMapStats[value]; - const selectedStat = statNameList?.[0]?.value; - setContextState({ metric: value, stat: selectedStat }); - setStatNameList(statNameList); - }; - - // 统计量选择 - const onSelectStatChange = (value: string) => { - setContextState({ stat: value }); - }; - - // 维度选择 - const onSelectDimensionChange = (value: string) => { - const params: ValuesRequestParamsType = { - metric, - stat, - dimension: value, - value: 0, - } as ValuesRequestParamsType; - updateDimensionValueList(params); - }; - // 维度值选择 - const onSelectDimensionValueChange = (value: string) => { - setContextState({ dimensionValue: value }); - }; - - return ( -
-
设置
-
- - - - - - setContextState({ - heatMapType: value, - }) - } - options={HEATMAP_TYPE} - /> -
-
- ); -}; - -export default memo(Controller); diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/type/index.d.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/type/index.d.ts deleted file mode 100644 index 4d396a0bd..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/type/index.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -export interface ControllerProps { - metrics: Array; -} - -export interface ValuesResponseType { - data?: { - [string]: string; - }; - error?: string; -} - -export interface HeatmapDataResponseType { - data?: Array; - error?: string; -} - -export interface ValuesRequestParamsType { - metric: string; - stat: string; - dimension: string; - value: number; -} diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/useController.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/useController.ts deleted file mode 100644 index c2ff9d1f3..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/controller/useController.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import request from '../utils/request'; -import { ValuesResponseType, ValuesRequestParamsType, HeatmapDataResponseType } from './type'; - -const useController = () => { - const loadGraphData = async (params: ValuesRequestParamsType) => { - try { - const result = await request({ - url: 'heatmap_data', - method: 'GET', - params, - }) as unknown as HeatmapDataResponseType; - return result; - } catch (error) { - return { - error: '网络异常:获取维度值列表失败', - }; - } - }; - const loadDimensionValueList = async (params: ValuesRequestParamsType) => { - if (!params.dimension || !params.metric || !params.stat) { - return {}; - } - try { - const result: ValuesResponseType = (await request({ - url: 'values', - method: 'GET', - params, - })) as unknown as ValuesResponseType; - return result; - } catch (error) { - return { - error: '网络异常:获取维度值列表失败', - }; - } - }; - return { - loadGraphData, - loadDimensionValueList, - }; -}; - -export default useController; diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/HeatMap/index.tsx b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/HeatMap/index.tsx deleted file mode 100644 index 9429beb08..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/HeatMap/index.tsx +++ /dev/null @@ -1,97 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import React, { useRef, useEffect, useState, memo } from 'react'; -import { useShallow } from 'zustand/shallow'; -import ReactECharts from 'echarts-for-react'; -import { message } from 'antd'; -import { useGlobalStore } from '../../../store'; -import useHeatMap from './useHeatMap'; -import { isEmpty } from 'lodash'; -import { TrendRequestParams, TrendResponseData } from '../type'; -import { isEqual } from 'lodash'; - -const HeatMap = () => { - const useHeatMapInstance = useHeatMap(); - const { metric, stat, dimension, dimensionValue, heatMaphData, heatMapType, setContextState } = useGlobalStore( - useShallow((state) => ({ - metric: state.metric, - stat: state.stat, - dimension: state.dimension, - dimensionValue: state.dimensionValue, - heatMaphData: state.heatMaphData, - heatMapType: state.heatMapType, - setContextState: state.setContextState, - })), - (oldTreats, newTreats) => { - return ( - isEqual(oldTreats.heatMaphData, newTreats.heatMaphData) && isEqual(oldTreats.heatMapType, newTreats.heatMapType) - ); - }, - ); - - const [option, setOption] = useState({}); - const yAxisMapRef = useRef(new Map()); - - useEffect(() => { - if (!isEmpty(heatMaphData)) { - const { yAxisData, option } = useHeatMapInstance.updateHeatMap(heatMaphData, dimension, heatMapType); - setOption(option); - yAxisMapRef.current = yAxisData; - } - }, [heatMaphData, heatMapType]); - - const onChartClick = async (echartsParams) => { - const dimX = echartsParams.data[0]; - const dimY = yAxisMapRef.current[echartsParams.data[1]]; - const params: TrendRequestParams = { - metric: metric, - stat: stat, - dimension: dimension, - value: dimensionValue, - dimX, - dimYIdx: dimY, - } as TrendRequestParams; - setContextState({ loadingLineChart: true }); - const result: TrendResponseData = await useHeatMapInstance.loadGraphData(params); - setContextState({ loadingLineChart: false }); - if (result?.error) { - message.error(result.error); - return; - } - const trendData = result.data; - setContextState({ trendData, dimX, dimY }); - }; - - const onDataZoom = (params) => { - console.log(params); - }; - return ( -
- -
- ); -}; - -export default memo(HeatMap); diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/HeatMap/useHeatMap.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/HeatMap/useHeatMap.ts deleted file mode 100644 index eccbc1daf..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/HeatMap/useHeatMap.ts +++ /dev/null @@ -1,297 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import { DIMENSIONS_AXIS_MAP, CONTINUOUS } from '../../../common/constant'; -import { formatSegmentLabel } from '../../../utils'; -import request from '../../../utils/request'; -import type { TrendRequestParams, TrendResponseData } from '../type'; - -const useHeatMap = () => { - const loadGraphData = async (params: TrendRequestParams): Promise => { - try { - const result = await request({ - url: 'trend', - method: 'GET', - params, - }); - return result; - } catch (error) { - return { - error: '网络异常:获取维度值列表失败', - }; - } - }; - const calculate3SigmaPieces = (data) => { - const values = data.map((item) => item[2]).filter((v) => !isNaN(v) && isFinite(v)); - if (values.length === 0) return []; - - const mean = values.reduce((a, b) => a + b, 0) / values.length; - const stdDev = Math.sqrt(values.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / values.length); - - const segments = [ - { threshold: mean - 3 * stdDev, color: '#313695' }, - { threshold: mean - 2 * stdDev, color: '#4575b4' }, - { threshold: mean - stdDev, color: '#74add1' }, - // { threshold: mean, color: '#abd9e9' }, - { threshold: mean + stdDev, color: '#ffffbf' }, - { threshold: mean + 2 * stdDev, color: '#fdae61' }, - { threshold: mean + 3 * stdDev, color: '#f46d43' }, - { threshold: Infinity, color: '#d73027' }, - ]; - - const pieces: Array<{ - min: number; - max: number; - label: string; - color: string; - }> = []; - let prevThreshold = -Infinity; - - segments.forEach((segment) => { - if (segment.threshold > prevThreshold) { - pieces.push({ - min: prevThreshold, - max: segment.threshold, - label: formatSegmentLabel(prevThreshold, segment.threshold), - color: segment.color, - }); - prevThreshold = segment.threshold; - } - }); - - return pieces; - }; - const createVisualMapConfig = (data, mode, minValue, maxValue) => { - const values = data.map((item) => item[2]).filter((v) => !isNaN(v) && isFinite(v)); - if (values.length === 0) return {}; - - if (mode === CONTINUOUS) { - return { - type: 'continuous', - min: minValue, - max: maxValue, - inRange: { - color: [ - '#4575b4', - '#74add1', - '#abd9e9', - '#e0f3f8', - '#ffffbf', - '#fee090', - '#fdae61', - '#f46d43', - '#d73027', - '#a50026', - ], - }, - orient: 'horizontal', - left: 'center', - textStyle: { - color: '#666', - }, - calculable: true, - itemWidth: 20, - itemHeight: 800, - precision: 12, - top: 20, - }; - } else { - // 分段模式 - return { - type: 'piecewise', - pieces: calculate3SigmaPieces(data), - orient: 'horizontal', - left: 'center', - itemGap: 7, - itemSymbol: 'rect', - textStyle: { - fontSize: 10, - color: '#666', - }, - inRange: { - color: [], - }, - top: 20, - }; - } - }; - - const updateHeatMap = (data, dimension, heatMapType) => { - const ModuleNameMap = new Map(); // ID -> ModuleName - const yAxisMap = new Map(); // ID -> Index - let heatMapChartData = data.map((entry) => { - ModuleNameMap.set(entry[1][0], entry[1][1]); - return [entry[0], entry[1][0], entry[2]]; - }); - - // x轴和y轴的刻度 - const xAxisSet = new Set(); - const yAxisData = Array.from(ModuleNameMap.keys()).sort((a: number, b: number) => a - b); - yAxisData.forEach((id, index) => { - yAxisMap.set(id, index); - }); - heatMapChartData = heatMapChartData.map((entry) => { - return [entry[0], yAxisMap.get(entry[1]), entry[2]]; - }); - // x轴和y轴的标签 - const xAxisName = DIMENSIONS_AXIS_MAP[dimension]?.x; - const yAxisName = DIMENSIONS_AXIS_MAP[dimension]?.y; - - let minValue = Number.MAX_VALUE; - let maxValue = Number.MIN_VALUE; - heatMapChartData.forEach((entry) => { - xAxisSet.add(entry[0]); - minValue = Math.min(minValue, entry[2]); - maxValue = Math.max(maxValue, entry[2]); - }); - const xAxisData = Array.from(xAxisSet).sort((a: number, b: number) => a - b); - - // 配置项 - const option = { - backgroundColor: '#fff', - tooltip: { - position: 'top', - formatter: (params) => { - const xLabel = params.data[0]; - const yLabel = ModuleNameMap.get(yAxisData[params.data[1]]); - return ` -
${yAxisName}: ${yLabel}
-
${xAxisName}: ${xLabel}
-
Value: ${params.data[2].toFixed(12)}
- `; - }, - backgroundColor: 'rgba(50,50,50,0.7)', - borderColor: '#333', - textStyle: { - color: '#fff', - fontSize: 12, - }, - extraCssText: 'box-shadow: 0 0 10px rgba(0,0,0,0.3);border-radius:4px;padding:8px;', - }, - - grid: { - height: '80%', - width: '90%', - left: '5%', - top: '12%' - }, - - xAxis: { - type: 'category', - name: xAxisName, - data: xAxisData, - splitArea: { - show: true, - }, - - axisLabel: { - formatter: (value) => (value.length > 20 ? value.slice(0, 8) + '...' : value), - rotate: 45, - fontSize: 11, - color: '#666', - fontWeight: 'bold', - }, - show: true, - nameLocation: 'end', - nameGap: 30, - axisTick: { - alignWithLabel: true, - }, - nameTextStyle: { - fontSize: 12, - fontWeight: 'bold', - color: '#444', - }, - }, - yAxis: { - type: 'category', - name: yAxisName, - data: yAxisData, - offset: 4, - show: true, - nameLocation: 'end', - nameGap: 20, - axisLabel: { - fontSize: 11, - fontWeight: 'bold', - color: '#666', - formatter: (value) => { - return value.length > 15 ? value.slice(0, 8) + '...' : value; - }, - }, - nameTextStyle: { - fontSize: 12, - fontWeight: 'bold', - color: '#444', - }, - }, - visualMap: createVisualMapConfig(heatMapChartData, heatMapType, minValue, maxValue), - dataZoom: [ - { - type: 'slider', - show: true, - startValue: 0, - endValue: 500, - bottom: 30, - realtime: false, - }, - { - type: 'inside', - startValue: 0, - endValue: 500, - }, - { - type: 'slider', - show: true, - yAxisIndex: 0, - filterMode: 'empty', - handleSize: 8, - showDataShadow: false, - left: '20', - start: 0, - end: 100, - }, - ], - series: [ - { - name: 'Heatmap', - type: 'heatmap', - data: heatMapChartData, - label: { - show: false, - }, - emphasis: { - itemStyle: { - shadowBlur: 10, - shadowColor: 'rgba(0, 0, 0, 0.5)', - }, - }, - progressive: 300, - animation: true, - }, - ], - animation: true, - animationDuration: 300, - animationEasing: 'cubicInOut', - }; - - return { yAxisData, option }; - }; - - return { updateHeatMap, loadGraphData }; -}; -export default useHeatMap; diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/LineChart/index.tsx b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/LineChart/index.tsx deleted file mode 100644 index 8f38a695b..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/LineChart/index.tsx +++ /dev/null @@ -1,140 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import React, { memo } from 'react'; -import ReactECharts from 'echarts-for-react'; -import { useGlobalStore } from '../../../store'; -import { useShallow, shallow } from 'zustand/shallow'; -import { DIMENSIONS_AXIS_MAP, MODULE_NAME_DIMENSION } from '../../../common/constant'; - -const LineChart = () => { - const { metric, stat, dimension, trendData, dimX, dimY } = useGlobalStore( - useShallow((state) => ({ - metric: state.metric, - stat: state.stat, - dimension: state.dimension, - trendData: state.trendData, - dimX: state.dimX, - dimY: state.dimY, - })), - shallow, - ); - const heatMapXAxisName = DIMENSIONS_AXIS_MAP[dimension || '']?.x; - const heatMapYAxisName = DIMENSIONS_AXIS_MAP[dimension || '']?.y; - let yAxisMap = new Map(); - let xAxisData = trendData?.dimensions; - let xAxisName = dimension; - if (dimension === MODULE_NAME_DIMENSION) { - xAxisName = 'Target Id'; - trendData?.dimensions.forEach((item, index) => { - yAxisMap.set(String(index), item); - }); - xAxisData = Array.from(yAxisMap.keys()); - } - - const option = { - title: { - text: `${metric} 分布图 (${heatMapXAxisName}: ${dimX || ' '} / ${heatMapYAxisName}: ${dimY || ' '}) `, - left: 'center', - top: '2%', - textStyle: { - fontSize: 14, - color: '#666', - fontWeight: 'bold', - }, - }, - grid: { - width: '90%', - top: '20%', - left: '5%', - }, - tooltip: { - trigger: 'axis', - formatter: (params) => { - const yAxisValue = params[0]?.data; - const dimensionValue = params[0]?.axisValue; - const xAxisLabel = dimension === MODULE_NAME_DIMENSION ? 'Module Name' : xAxisName; - const xAxisValue = dimension === MODULE_NAME_DIMENSION ? yAxisMap.get(dimensionValue) : dimensionValue; - return ` -
${xAxisLabel}: ${xAxisValue}
-
${stat}: ${yAxisValue}
- `; - }, - }, - xAxis: { - type: 'category', - data: xAxisData, - name: xAxisName, - axisLabel: { - rotate: 45, - fontSize: 12, - fontWeight: 'bold', - }, - nameTextStyle: { - fontSize: 12, - fontWeight: 'bold', - color: '#444', - }, - }, - yAxis: { - type: 'value', - name: stat, - axisLabel: { - fontSize: 12, - fontWeight: 'bold', - formatter: (value) => { - if (value === 0) return '0'; - const absValue = Math.abs(value); - if (absValue < 1e-4 || absValue >= 1e4) { - return value.toExponential(4); - } else { - let str = value.toFixed(4); - str = str.replace(/(\.\d*?[1-9])0+$/, '$1').replace(/\.$/, ''); - return str; - } - }, - }, - nameTextStyle: { - fontSize: 12, - fontWeight: 'bold', - color: '#444', - }, - }, - series: [ - { - name: '趋势', - type: 'line', - data: trendData?.values, - lineStyle: { - width: 2, - }, - progressive: 1000, - animation: true, - }, - ], - animation: true, - animationDuration: 1000, - animationEasing: 'cubicInOut', - }; - return ( -
- -
- ); -}; - -export default memo(LineChart); diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/type/index.d.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/type/index.d.ts deleted file mode 100644 index 10b5cd939..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/components/type/index.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ -export type TrendRequestParams = { - metric: string; - stat: string; - dimension: string; - value: string; - dimX: string; - dimYIdx: string; -}; - -export type TrendResponseData = { - data?: { - dimensions: string[]; - values: string[]; - }; - error?: string; -}; diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/index.less b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/index.less deleted file mode 100644 index ac7dfd6df..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/index.less +++ /dev/null @@ -1,41 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -.graph-container { - width: 100%; - height: 100%; - display: flex; - flex-direction: column; - justify-content: space-between; - - .graph-title { - font-size: 16px; - font-weight: 500; - text-align: center; - padding-block: 6px; - background-color: #f1f1f1; - } -} - -.main-graph { - width: 100%; - height: 100%; - display: flex; - flex-direction: column; - justify-content: space-between; - overflow: hidden; -} \ No newline at end of file diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/index.tsx b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/index.tsx deleted file mode 100644 index 689e91746..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/graph/index.tsx +++ /dev/null @@ -1,50 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import React, { memo } from 'react'; -import { Spin } from 'antd'; -import { useShallow, shallow } from 'zustand/shallow'; -import { useGlobalStore } from '../store'; -import HeatMap from './components/HeatMap'; -import LineChart from './components/LineChart'; - -import './index.less'; - -const Graph = () => { - const { loadingHeatMap, loadingLineChart } = useGlobalStore( - useShallow((state) => ({ - loadingHeatMap: state.loadingHeatMap, - loadingLineChart: state.loadingLineChart, - })), - shallow, - ); - return ( -
-
模型监控数据看板
-
- - - - - - -
-
- ); -}; - -export default memo(Graph); diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/index.tsx b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/index.tsx deleted file mode 100644 index e7b152719..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/index.tsx +++ /dev/null @@ -1,26 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import React from 'react'; -import ReactDOM from 'react-dom/client'; -import MonVis from './main'; - -const rootElement = document.getElementById('root'); -if (rootElement) { - const root = ReactDOM.createRoot(rootElement); - root.render(); -} diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/index.less b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/index.less deleted file mode 100644 index 408597b46..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/index.less +++ /dev/null @@ -1,26 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -.sider { - background-color: #e2e1e1; - padding-inline: 1px; - min-width: 260px !important; -} - -.content { - background-color: white; -} \ No newline at end of file diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/index.tsx b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/index.tsx deleted file mode 100644 index c5eaffdd3..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/index.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import React, { useEffect, useState, memo } from 'react'; -import { Layout } from 'antd'; -import Controller from '../controller'; -import Graph from '../graph'; -import { message } from 'antd'; -import './index.less'; -import request from '../utils/request'; -import { isEmpty } from 'lodash'; -import type { MetricsResponseType } from './type'; -const { Sider, Content } = Layout; - -const MonVis = () => { - const [metrics, setMetrics] = useState([]); - - // API获取指标信息 - const loadIndicatorsInfo = async () => { - try { - const { data } = (await request({ url: 'metrics', method: 'GET' })) as unknown as MetricsResponseType; - if (!isEmpty(data)) { - setMetrics(data); - } - } catch (error) { - message.error('网络异常:获取指标信息失败'); - } - }; - - useEffect(() => { - loadIndicatorsInfo(); - }, []); - - return ( - - - - - - - - - ); -}; - -export default memo(MonVis); diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/type/index.d.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/type/index.d.ts deleted file mode 100644 index 9ac2f7d08..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/main/type/index.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -export interface MetricsResponseType { - success: boolean; - data: Array; -} - -export interface metricsDataType { - name: string; - stats: string[]; -} diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/store/index.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/store/index.ts deleted file mode 100644 index 79b5345c0..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/store/index.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -import { createWithEqualityFn } from 'zustand/traditional'; -import { CONTINUOUS } from '../common/constant'; -import type { ContextStateType } from '../common/type'; - -// 使用createWithEqualityFn而不是create -export const useGlobalStore = createWithEqualityFn( - (set) => ({ - heatMaphData: [], - trendData: { dimensions: [], values: [] }, - metric: '', - stat: '', - dimension: '', - dimensionValue: '', - heatMapType: CONTINUOUS, - dimX: '', - dimY: '', - loadingHeatMap: false, - loadingLineChart: false, - setContextState: (newState) => set((state) => ({ ...state, ...newState })), - }), - Object.is, // 指定默认的相等性函数,可以是浅层比较 -); diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/utils/index.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/utils/index.ts deleted file mode 100644 index d899bc245..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/utils/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ -export const formatSegmentLabel = (min, max) => { - const format = (value) => { - if (value === Infinity) return '∞'; - if (value === -Infinity) return '-∞'; - return value.toExponential(2); - }; - - if (min === -Infinity) return `< ${format(max)}`; - if (max === Infinity) return `> ${format(min)}`; - return `${format(min)} ~ ${format(max)}`; -}; diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/utils/request.ts b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/utils/request.ts deleted file mode 100644 index 84c23efb6..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/src/utils/request.ts +++ /dev/null @@ -1,91 +0,0 @@ -/* Copyright (c) 2025, Huawei Technologies. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import axios, { AxiosResponse, AxiosError } from 'axios'; -interface RequestOptions { - url: string; // 请求地址 - method?: 'GET' | 'POST' | 'PUT' | 'DELETE'; // 请求方法,默认为 GET - data?: any; // 请求体数据(适用于 POST、PUT) - params?: any; // URL 参数(适用于 GET) - headers?: Record; // 自定义请求头 - timeout?: number; // 超时时间(毫秒),默认 10 秒 -} -interface ApiResponse { - success: boolean; // 是否成功 - data?: T; // 响应数据 - error?: string; // 错误信息 -} -export default async function request(options: RequestOptions): Promise> { - const { url, method = 'GET', data = null, params = null, headers = {}, timeout = 60000 * 3 } = options; - - try { - const controller = new AbortController(); - const signal = controller.signal; - const timeoutId = setTimeout(() => controller.abort(), timeout); - const response: AxiosResponse = await axios({ - url, - method, - data, - params, - headers: { - 'Content-Type': 'application/json', // 默认 Content-Type - ...headers, // 自定义请求头覆盖默认值 - }, - maxBodyLength: Infinity, // 允许发送大文件 - signal, // 绑定信号以支持超时 - }); - - clearTimeout(timeoutId); - if (response.status >= 200 && response.status < 300) { - return response.data as ApiResponse; - } else { - return { - success: false, - error: `HTTP Error: ${response.status} - ${response.statusText}`, - }; - } - } catch (error) { - if (axios.isAxiosError(error)) { - const axiosError = error as AxiosError; - if (axiosError.code === 'ECONNABORTED') { - return { - success: false, - error: '请求超时,请稍后重试。', - }; - } else if (axiosError.response) { - const { status, statusText } = axiosError.response; - return { - success: false, - error: `HTTP Error: ${status} - ${statusText}`, - }; - } else if (axiosError.request) { - return { - success: false, - error: '网络错误,未收到服务器响应。', - }; - } else { - return { - success: false, - error: axiosError.message || '未知错误', - }; - } - } else { - return { - success: false, - error: (error as Error).message || '未知错误', - }; - } - } -} diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/tsconfig.json b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/tsconfig.json deleted file mode 100644 index 15fb526ae..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/tsconfig.json +++ /dev/null @@ -1,40 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ -{ - "compilerOptions": { - "jsx": "react", - "downlevelIteration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "importHelpers": true, - "inlineSourceMap": true, - "lib": [ - "dom", - "ES2022", - "dom.iterable" - ], - "moduleResolution": "node", - "module": "ES2022", - "noFallthroughCasesInSwitch": true, - "noImplicitReturns": true, - "noImplicitOverride": true, - "skipLibCheck": true, - "strict": true, - "noImplicitAny": false, - "target": "es2018" - } -} \ No newline at end of file diff --git a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/webpack.config.js b/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/webpack.config.js deleted file mode 100644 index e52a714e3..000000000 --- a/plugins/tensorboard-plugins/tb_graph_ascend/monvis_plugin/fe/webpack.config.js +++ /dev/null @@ -1,81 +0,0 @@ -/* ------------------------------------------------------------------------- - Copyright (c) 2025, Huawei Technologies. - All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---------------------------------------------------------------------------------------------*/ - -const path = require('path'); -const HtmlWebpackPlugin = require('html-webpack-plugin'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const InlineChunkHtmlPlugin = require('inline-chunk-html-plugin'); - -module.exports = { - entry: { - app: './src/index.tsx', - }, - output: { - filename: 'index.js', - path: path.resolve(__dirname, 'dist'), - }, - module: { - rules: [ - { - test: /\.(html)$/, - use: { - loader: 'html-loader', - }, - }, - { - test: /\.tsx?$/, - use: { - loader: 'ts-loader', - options: { - transpileOnly: true, - }, - }, - exclude: /node_modules/, - }, - { - test: /\.css$/i, - use: ['style-loader', 'css-loader'], - }, - { - test: /\.less$/i, - use: [ - 'style-loader', // 将 JS 字符串生成为