You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 6.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import ConfigInfo, { type BasicInfoData } from '@/components/ConfigInfo';
  2. import { AutoMLTaskType, autoMLTaskTypeOptions } from '@/enums';
  3. import { useComputingResource } from '@/hooks/useComputingResource';
  4. import {
  5. classifierAlgorithms,
  6. FrameworkType,
  7. frameworkTypeOptions,
  8. queryStrategies,
  9. regressorAlgorithms,
  10. } from '@/pages/ActiveLearn/components/CreateForm/utils';
  11. import { ActiveLearnData } from '@/pages/ActiveLearn/types';
  12. import { experimentStatusInfo } from '@/pages/Experiment/status';
  13. import { type NodeStatus } from '@/types';
  14. import { elapsedTime } from '@/utils/date';
  15. import {
  16. formatBoolean,
  17. formatCodeConfig,
  18. formatDataset,
  19. formatDate,
  20. formatEnum,
  21. formatMirror,
  22. formatModel,
  23. } from '@/utils/format';
  24. import { Flex } from 'antd';
  25. import classNames from 'classnames';
  26. import { useMemo } from 'react';
  27. import styles from './index.less';
  28. type BasicInfoProps = {
  29. info?: ActiveLearnData;
  30. className?: string;
  31. isInstance?: boolean;
  32. runStatus?: NodeStatus;
  33. };
  34. function BasicInfo({ info, className, runStatus, isInstance = false }: BasicInfoProps) {
  35. const getResourceDescription = useComputingResource()[1];
  36. const basicDatas: BasicInfoData[] = useMemo(() => {
  37. if (!info) {
  38. return [];
  39. }
  40. return [
  41. {
  42. label: '实验名称',
  43. value: info.name,
  44. },
  45. {
  46. label: '实验描述',
  47. value: info.description,
  48. },
  49. {
  50. label: '创建人',
  51. value: info.create_by,
  52. },
  53. {
  54. label: '创建时间',
  55. value: info.create_time,
  56. format: formatDate,
  57. },
  58. {
  59. label: '更新时间',
  60. value: info.update_time,
  61. format: formatDate,
  62. },
  63. ];
  64. }, [info]);
  65. const configDatas: BasicInfoData[] = useMemo(() => {
  66. if (!info) {
  67. return [];
  68. }
  69. const modelInfo = [
  70. {
  71. label: '预训练模型',
  72. value: info.model,
  73. format: formatModel,
  74. },
  75. {
  76. label: '模型文件路径',
  77. value: info.model_py,
  78. },
  79. {
  80. label: '模型类名称',
  81. value: info.model_class_name,
  82. },
  83. {
  84. label: 'epochs',
  85. value: info.epochs,
  86. },
  87. {
  88. label: 'batch_size',
  89. value: info.batch_size,
  90. },
  91. ];
  92. const lossInfo = [
  93. {
  94. label: '学习率',
  95. value: info.lr,
  96. },
  97. {
  98. label: 'loss文件路径',
  99. value: info.loss_py,
  100. },
  101. {
  102. label: 'loss类名',
  103. value: info.loss_class_name,
  104. },
  105. ];
  106. const algorithmInfo = [
  107. {
  108. label: info.task_type === AutoMLTaskType.Regression ? '回归算法' : '分类算法',
  109. value:
  110. info.task_type === AutoMLTaskType.Regression ? info.regressor_alg : info.classifier_alg,
  111. format: formatEnum(
  112. info.task_type === AutoMLTaskType.Regression ? regressorAlgorithms : classifierAlgorithms,
  113. ),
  114. },
  115. ];
  116. const diffInfo =
  117. info.framework_type === FrameworkType.Pytorch
  118. ? [...modelInfo, ...lossInfo]
  119. : info.framework_type === FrameworkType.Keras
  120. ? modelInfo
  121. : algorithmInfo;
  122. return [
  123. {
  124. label: '任务类型',
  125. value: info.task_type,
  126. format: formatEnum(autoMLTaskTypeOptions),
  127. },
  128. {
  129. label: '代码配置',
  130. value: info.code_config,
  131. format: formatCodeConfig,
  132. },
  133. {
  134. label: '数据集',
  135. value: info.dataset,
  136. format: formatDataset,
  137. },
  138. {
  139. label: '数据集处理文件路径',
  140. value: info.dataset_py,
  141. },
  142. {
  143. label: '数据集类名',
  144. value: info.dataset_class_name,
  145. },
  146. {
  147. label: '镜像',
  148. value: info.image,
  149. format: formatMirror,
  150. },
  151. {
  152. label: '资源规格',
  153. value: info.computing_resource_id,
  154. format: getResourceDescription,
  155. },
  156. {
  157. label: '框架类型',
  158. value: info.framework_type,
  159. format: formatEnum(frameworkTypeOptions),
  160. },
  161. ...diffInfo,
  162. {
  163. label: '是否打乱',
  164. value: info.shuffle,
  165. format: formatBoolean,
  166. },
  167. {
  168. label: '数据量',
  169. value: info.data_size,
  170. },
  171. {
  172. label: '训练集数据量',
  173. value: info.train_size,
  174. },
  175. {
  176. label: '初始训练数据量',
  177. value: info.initial_num,
  178. },
  179. {
  180. label: '查询次数',
  181. value: info.queries_num,
  182. },
  183. {
  184. label: '每次查询数据量',
  185. value: info.instances_num,
  186. },
  187. {
  188. label: '查询策略',
  189. value: info.query_strategy,
  190. format: formatEnum(queryStrategies),
  191. },
  192. {
  193. label: '检查点轮数',
  194. value: info.checkpoint_num,
  195. },
  196. ];
  197. }, [info, getResourceDescription]);
  198. const instanceDatas = useMemo(() => {
  199. if (!info || !runStatus) {
  200. return [];
  201. }
  202. return [
  203. {
  204. label: '启动时间',
  205. value: formatDate(info.create_time),
  206. ellipsis: true,
  207. },
  208. {
  209. label: '执行时长',
  210. value: elapsedTime(info.create_time, runStatus.finishedAt),
  211. ellipsis: true,
  212. },
  213. {
  214. label: '状态',
  215. value: (
  216. <Flex align="center">
  217. <img
  218. style={{ width: '17px', marginRight: '7px' }}
  219. src={experimentStatusInfo[runStatus.phase]?.icon}
  220. draggable={false}
  221. alt=""
  222. />
  223. <div
  224. style={{
  225. color: experimentStatusInfo[runStatus?.phase]?.color,
  226. fontSize: '15px',
  227. lineHeight: 1.6,
  228. }}
  229. >
  230. {experimentStatusInfo[runStatus?.phase]?.label}
  231. </div>
  232. </Flex>
  233. ),
  234. ellipsis: true,
  235. },
  236. ];
  237. }, [runStatus, info]);
  238. return (
  239. <div className={classNames(styles['active-learn-basic'], className)}>
  240. {isInstance && runStatus && (
  241. <ConfigInfo
  242. title="运行信息"
  243. datas={instanceDatas}
  244. labelWidth={70}
  245. style={{ marginBottom: '20px' }}
  246. />
  247. )}
  248. {!isInstance && (
  249. <ConfigInfo
  250. title="基本信息"
  251. datas={basicDatas}
  252. labelWidth={70}
  253. style={{ marginBottom: '20px' }}
  254. />
  255. )}
  256. <ConfigInfo
  257. title="配置信息"
  258. datas={configDatas}
  259. labelWidth={120}
  260. style={{ marginBottom: '20px' }}
  261. ></ConfigInfo>
  262. </div>
  263. );
  264. }
  265. export default BasicInfo;