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.

test_model.py 22 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. # Copyright 2019 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """
  16. Function:
  17. Test the query module about lineage information.
  18. Usage:
  19. The query module test should be run after lineagemgr/collection/model/test_model_lineage.py
  20. pytest lineagemgr
  21. """
  22. import os
  23. from unittest import TestCase
  24. import pytest
  25. from mindinsight.lineagemgr.model import filter_summary_lineage
  26. from mindinsight.datavisual.data_transform import data_manager
  27. from mindinsight.lineagemgr.cache_item_updater import LineageCacheItemUpdater
  28. from mindinsight.lineagemgr.common.exceptions.exceptions import LineageSearchConditionParamError
  29. from mindinsight.lineagemgr.model import get_flattened_lineage
  30. from .conftest import BASE_SUMMARY_DIR, DATASET_GRAPH, SUMMARY_DIR, SUMMARY_DIR_2, LINEAGE_DATA_MANAGER
  31. from ....ut.lineagemgr.querier import event_data
  32. from ....utils.tools import assert_equal_lineages, get_relative_path
  33. LINEAGE_INFO_RUN1 = {
  34. 'summary_dir': './run1',
  35. 'metric': {
  36. 'accuracy': 0.78
  37. },
  38. 'hyper_parameters': {
  39. 'optimizer': 'Momentum',
  40. 'learning_rate': 0.12,
  41. 'loss_function': 'SoftmaxCrossEntropyWithLogits',
  42. 'epoch': 14,
  43. 'parallel_mode': 'stand_alone',
  44. 'device_num': 2,
  45. 'batch_size': 32
  46. },
  47. 'algorithm': {
  48. 'network': 'ResNet'
  49. },
  50. 'train_dataset': {
  51. 'train_dataset_size': 1024
  52. },
  53. 'valid_dataset': {
  54. 'valid_dataset_size': 1024
  55. },
  56. 'model': {
  57. 'path': '{"ckpt": "'
  58. + BASE_SUMMARY_DIR + '/run1/CKPtest_model.ckpt"}',
  59. 'size': 64
  60. },
  61. 'dataset_graph': DATASET_GRAPH
  62. }
  63. LINEAGE_FILTRATION_EXCEPT_RUN = {
  64. 'summary_dir': './except_run',
  65. 'model_lineage': {
  66. 'loss_function': 'SoftmaxCrossEntropyWithLogits',
  67. 'train_dataset_path': None,
  68. 'train_dataset_count': 1024,
  69. 'test_dataset_path': None,
  70. 'test_dataset_count': None,
  71. 'user_defined': {},
  72. 'network': 'ResNet',
  73. 'optimizer': 'Momentum',
  74. 'learning_rate': 0.12,
  75. 'epoch': 10,
  76. 'batch_size': 32,
  77. 'device_num': 2,
  78. 'loss': 0.03,
  79. 'model_size': 64,
  80. 'metric': {},
  81. 'dataset_mark': 2
  82. },
  83. 'dataset_graph': DATASET_GRAPH,
  84. 'added_info': {}
  85. }
  86. LINEAGE_FILTRATION_RUN1 = {
  87. 'summary_dir': './run1',
  88. 'model_lineage': {
  89. 'loss_function': 'SoftmaxCrossEntropyWithLogits',
  90. 'train_dataset_path': None,
  91. 'train_dataset_count': 1024,
  92. 'test_dataset_path': None,
  93. 'test_dataset_count': 1024,
  94. 'user_defined': {
  95. 'info': 'info1',
  96. 'version': 'v1'
  97. },
  98. 'network': 'ResNet',
  99. 'optimizer': 'Momentum',
  100. 'learning_rate': 0.12,
  101. 'epoch': 14,
  102. 'batch_size': 32,
  103. 'device_num': 2,
  104. 'loss': None,
  105. 'model_size': 64,
  106. 'metric': {
  107. 'accuracy': 0.78
  108. },
  109. 'dataset_mark': 2
  110. },
  111. 'dataset_graph': DATASET_GRAPH,
  112. 'added_info': {}
  113. }
  114. LINEAGE_FILTRATION_RUN2 = {
  115. 'summary_dir': './run2',
  116. 'model_lineage': {
  117. 'loss_function': "SoftmaxCrossEntropyWithLogits",
  118. 'train_dataset_path': None,
  119. 'train_dataset_count': 1024,
  120. 'test_dataset_path': None,
  121. 'test_dataset_count': 1024,
  122. 'user_defined': {
  123. 'info': 'info1',
  124. 'version': 'v1',
  125. 'eval_version': 'version2'
  126. },
  127. 'network': "ResNet",
  128. 'optimizer': "Momentum",
  129. 'learning_rate': 0.12,
  130. 'epoch': 10,
  131. 'batch_size': 32,
  132. 'device_num': 2,
  133. 'loss': 0.03,
  134. 'model_size': 10,
  135. 'metric': {
  136. 'accuracy': 2.78
  137. },
  138. 'dataset_mark': 3
  139. },
  140. 'dataset_graph': DATASET_GRAPH,
  141. 'added_info': {}
  142. }
  143. @pytest.mark.usefixtures("create_summary_dir")
  144. class TestModelApi(TestCase):
  145. """Test lineage information query interface."""
  146. @classmethod
  147. def setup_class(cls):
  148. """The initial process."""
  149. cls._dir_with_empty_lineage = os.path.join(
  150. BASE_SUMMARY_DIR, 'dir_with_empty_lineage'
  151. )
  152. os.makedirs(cls._dir_with_empty_lineage)
  153. ms_file = os.path.join(
  154. cls._dir_with_empty_lineage, 'empty.summary.1581499502.bms_MS'
  155. )
  156. lineage_file = ms_file + '_lineage'
  157. with open(ms_file, mode='w'):
  158. pass
  159. with open(lineage_file, mode='w'):
  160. pass
  161. empty_dir = os.path.join(BASE_SUMMARY_DIR, 'empty_dir')
  162. os.makedirs(empty_dir)
  163. cls._empty_train_id = get_relative_path(empty_dir, LINEAGE_DATA_MANAGER.summary_base_dir)
  164. LINEAGE_DATA_MANAGER.start_load_data().join()
  165. @pytest.mark.level0
  166. @pytest.mark.platform_arm_ascend_training
  167. @pytest.mark.platform_x86_gpu_training
  168. @pytest.mark.platform_x86_ascend_training
  169. @pytest.mark.platform_x86_cpu
  170. @pytest.mark.env_single
  171. def test_filter_summary_lineage(self):
  172. """Test the interface of filter_summary_lineage."""
  173. expect_result = {
  174. 'customized': event_data.CUSTOMIZED__1,
  175. 'object': [
  176. LINEAGE_FILTRATION_EXCEPT_RUN,
  177. LINEAGE_FILTRATION_RUN1,
  178. LINEAGE_FILTRATION_RUN2
  179. ],
  180. 'count': 3
  181. }
  182. search_condition = {
  183. 'sorted_name': 'summary_dir'
  184. }
  185. res = filter_summary_lineage(data_manager=LINEAGE_DATA_MANAGER, search_condition=search_condition)
  186. expect_objects = expect_result.get('object')
  187. for idx, res_object in enumerate(res.get('object')):
  188. expect_objects[idx]['model_lineage']['dataset_mark'] = res_object['model_lineage'].get('dataset_mark')
  189. assert_equal_lineages(expect_result, res, self.assertDictEqual)
  190. @pytest.mark.level0
  191. @pytest.mark.platform_arm_ascend_training
  192. @pytest.mark.platform_x86_gpu_training
  193. @pytest.mark.platform_x86_ascend_training
  194. @pytest.mark.platform_x86_cpu
  195. @pytest.mark.env_single
  196. def test_filter_summary_lineage_with_condition_1(self):
  197. """Test the interface of filter_summary_lineage with condition."""
  198. search_condition = {
  199. 'summary_dir': {
  200. 'in': [
  201. get_relative_path(SUMMARY_DIR, LINEAGE_DATA_MANAGER.summary_base_dir),
  202. get_relative_path(SUMMARY_DIR_2, LINEAGE_DATA_MANAGER.summary_base_dir)
  203. ]
  204. },
  205. 'metric/accuracy': {
  206. 'lt': 3.0,
  207. 'gt': 0.5
  208. },
  209. 'sorted_name': 'metric/accuracy',
  210. 'sorted_type': 'descending',
  211. 'limit': 3,
  212. 'offset': 0
  213. }
  214. expect_result = {
  215. 'customized': event_data.CUSTOMIZED__1,
  216. 'object': [
  217. LINEAGE_FILTRATION_RUN2,
  218. LINEAGE_FILTRATION_RUN1
  219. ],
  220. 'count': 2
  221. }
  222. partial_res = filter_summary_lineage(data_manager=LINEAGE_DATA_MANAGER, search_condition=search_condition)
  223. expect_objects = expect_result.get('object')
  224. for idx, res_object in enumerate(partial_res.get('object')):
  225. expect_objects[idx]['model_lineage']['dataset_mark'] = res_object['model_lineage'].get('dataset_mark')
  226. assert_equal_lineages(expect_result, partial_res, self.assertDictEqual)
  227. @pytest.mark.level0
  228. @pytest.mark.platform_arm_ascend_training
  229. @pytest.mark.platform_x86_gpu_training
  230. @pytest.mark.platform_x86_ascend_training
  231. @pytest.mark.platform_x86_cpu
  232. @pytest.mark.env_single
  233. def test_filter_summary_lineage_with_condition_2(self):
  234. """Test the interface of filter_summary_lineage with condition."""
  235. search_condition = {
  236. 'summary_dir': {
  237. 'in': [
  238. './run1',
  239. './run2'
  240. ]
  241. },
  242. 'metric/accuracy': {
  243. 'lt': 3.0,
  244. 'gt': 0.5
  245. },
  246. 'sorted_name': 'metric/accuracy',
  247. 'sorted_type': 'descending',
  248. 'limit': 3,
  249. 'offset': 0
  250. }
  251. expect_result = {
  252. 'customized': event_data.CUSTOMIZED__1,
  253. 'object': [
  254. LINEAGE_FILTRATION_RUN2,
  255. LINEAGE_FILTRATION_RUN1
  256. ],
  257. 'count': 2
  258. }
  259. partial_res = filter_summary_lineage(data_manager=LINEAGE_DATA_MANAGER, search_condition=search_condition)
  260. expect_objects = expect_result.get('object')
  261. for idx, res_object in enumerate(partial_res.get('object')):
  262. expect_objects[idx]['model_lineage']['dataset_mark'] = res_object['model_lineage'].get('dataset_mark')
  263. assert_equal_lineages(expect_result, partial_res, self.assertDictEqual)
  264. @pytest.mark.level0
  265. @pytest.mark.platform_arm_ascend_training
  266. @pytest.mark.platform_x86_gpu_training
  267. @pytest.mark.platform_x86_ascend_training
  268. @pytest.mark.platform_x86_cpu
  269. @pytest.mark.env_single
  270. def test_filter_summary_lineage_with_condition_3(self):
  271. """Test the interface of filter_summary_lineage with condition."""
  272. search_condition1 = {
  273. 'batch_size': {
  274. 'ge': 30
  275. },
  276. 'sorted_name': 'metric/accuracy',
  277. }
  278. expect_result = {
  279. 'customized': event_data.CUSTOMIZED__1,
  280. 'object': [
  281. LINEAGE_FILTRATION_EXCEPT_RUN,
  282. LINEAGE_FILTRATION_RUN1,
  283. LINEAGE_FILTRATION_RUN2
  284. ],
  285. 'count': 3
  286. }
  287. partial_res1 = filter_summary_lineage(data_manager=LINEAGE_DATA_MANAGER, search_condition=search_condition1)
  288. expect_objects = expect_result.get('object')
  289. for idx, res_object in enumerate(partial_res1.get('object')):
  290. expect_objects[idx]['model_lineage']['dataset_mark'] = res_object['model_lineage'].get('dataset_mark')
  291. assert_equal_lineages(expect_result, partial_res1, self.assertDictEqual)
  292. search_condition2 = {
  293. 'batch_size': {
  294. 'lt': 30
  295. },
  296. 'lineage_type': {
  297. 'eq': 'model'
  298. },
  299. }
  300. expect_result = {
  301. 'customized': {},
  302. 'object': [],
  303. 'count': 0
  304. }
  305. partial_res2 = filter_summary_lineage(data_manager=LINEAGE_DATA_MANAGER, search_condition=search_condition2)
  306. assert expect_result == partial_res2
  307. @pytest.mark.level0
  308. @pytest.mark.platform_arm_ascend_training
  309. @pytest.mark.platform_x86_gpu_training
  310. @pytest.mark.platform_x86_ascend_training
  311. @pytest.mark.platform_x86_cpu
  312. @pytest.mark.env_single
  313. def test_filter_summary_lineage_condition_4(self):
  314. """Test the abnormal execution of the filter_summary_lineage interface."""
  315. expect_result = {
  316. 'customized': {},
  317. 'object': [],
  318. 'count': 0
  319. }
  320. search_condition = {
  321. 'summary_dir': {
  322. 'eq': self._empty_train_id
  323. }
  324. }
  325. res = filter_summary_lineage(data_manager=LINEAGE_DATA_MANAGER, search_condition=search_condition)
  326. assert expect_result == res
  327. @pytest.mark.level0
  328. @pytest.mark.platform_arm_ascend_training
  329. @pytest.mark.platform_x86_gpu_training
  330. @pytest.mark.platform_x86_ascend_training
  331. @pytest.mark.platform_x86_cpu
  332. @pytest.mark.env_single
  333. def test_filter_summary_lineage_with_lineage_type(self):
  334. """Test the interface of filter_summary_lineage with lineage_type."""
  335. train_id = './except_run'
  336. search_condition = {
  337. 'summary_dir': {
  338. 'in': [train_id]
  339. },
  340. 'lineage_type': {
  341. 'eq': 'dataset'
  342. },
  343. }
  344. expect_result = {
  345. 'customized': {},
  346. 'object': [
  347. {
  348. 'summary_dir': train_id,
  349. 'dataset_graph': DATASET_GRAPH,
  350. 'added_info': {}
  351. }
  352. ],
  353. 'count': 1
  354. }
  355. res = filter_summary_lineage(data_manager=LINEAGE_DATA_MANAGER, search_condition=search_condition)
  356. assert expect_result == res
  357. @pytest.mark.level0
  358. @pytest.mark.platform_arm_ascend_training
  359. @pytest.mark.platform_x86_gpu_training
  360. @pytest.mark.platform_x86_ascend_training
  361. @pytest.mark.platform_x86_cpu
  362. @pytest.mark.env_single
  363. def test_filter_summary_lineage_exception_2(self):
  364. """Test the abnormal execution of the filter_summary_lineage interface."""
  365. # search_condition type error
  366. search_condition = {
  367. 'summary_dir': 1.0
  368. }
  369. self.assertRaisesRegex(
  370. LineageSearchConditionParamError,
  371. 'The search_condition element summary_dir should be dict.',
  372. filter_summary_lineage,
  373. LINEAGE_DATA_MANAGER,
  374. None,
  375. search_condition
  376. )
  377. # only sorted_type (no sorted_name)
  378. search_condition = {
  379. 'sorted_type': 'descending'
  380. }
  381. self.assertRaisesRegex(
  382. LineageSearchConditionParamError,
  383. 'The sorted_name must exist when sorted_type exists.',
  384. filter_summary_lineage,
  385. LINEAGE_DATA_MANAGER,
  386. None,
  387. search_condition
  388. )
  389. # search condition is not dict or None
  390. search_condition = []
  391. self.assertRaisesRegex(
  392. LineageSearchConditionParamError,
  393. 'Invalid search_condition type, it should be dict.',
  394. filter_summary_lineage,
  395. LINEAGE_DATA_MANAGER,
  396. None,
  397. search_condition
  398. )
  399. # the condition of limit is invalid
  400. search_condition = {
  401. 'limit': True
  402. }
  403. self.assertRaisesRegex(
  404. LineageSearchConditionParamError,
  405. 'The limit must be int.',
  406. filter_summary_lineage,
  407. LINEAGE_DATA_MANAGER,
  408. None,
  409. search_condition
  410. )
  411. @pytest.mark.level0
  412. @pytest.mark.platform_arm_ascend_training
  413. @pytest.mark.platform_x86_gpu_training
  414. @pytest.mark.platform_x86_ascend_training
  415. @pytest.mark.platform_x86_cpu
  416. @pytest.mark.env_single
  417. def test_filter_summary_lineage_exception_3(self):
  418. """Test the abnormal execution of the filter_summary_lineage interface."""
  419. # the condition of offset is invalid
  420. search_condition = {
  421. 'offset': 1.0
  422. }
  423. self.assertRaisesRegex(
  424. LineageSearchConditionParamError,
  425. 'The offset must be int.',
  426. filter_summary_lineage,
  427. LINEAGE_DATA_MANAGER,
  428. None,
  429. search_condition
  430. )
  431. # the search attribute not supported
  432. search_condition = {
  433. 'dataset_graph': {
  434. 'le': 1
  435. }
  436. }
  437. self.assertRaisesRegex(
  438. LineageSearchConditionParamError,
  439. 'The search attribute not supported.',
  440. filter_summary_lineage,
  441. LINEAGE_DATA_MANAGER,
  442. None,
  443. search_condition
  444. )
  445. @pytest.mark.level0
  446. @pytest.mark.platform_arm_ascend_training
  447. @pytest.mark.platform_x86_gpu_training
  448. @pytest.mark.platform_x86_ascend_training
  449. @pytest.mark.platform_x86_cpu
  450. @pytest.mark.env_single
  451. def test_filter_summary_lineage_exception_4(self):
  452. """Test the abnormal execution of the filter_summary_lineage interface."""
  453. # the sorted_type not supported
  454. search_condition = {
  455. 'sorted_name': 'summary_dir',
  456. 'sorted_type': 'xxx'
  457. }
  458. self.assertRaisesRegex(
  459. LineageSearchConditionParamError,
  460. 'The sorted_type must be ascending or descending',
  461. filter_summary_lineage,
  462. LINEAGE_DATA_MANAGER,
  463. None,
  464. search_condition
  465. )
  466. # the search condition not supported
  467. search_condition = {
  468. 'batch_size': {
  469. 'dd': 30
  470. }
  471. }
  472. self.assertRaisesRegex(
  473. LineageSearchConditionParamError,
  474. 'The compare condition should be in',
  475. filter_summary_lineage,
  476. LINEAGE_DATA_MANAGER,
  477. None,
  478. search_condition
  479. )
  480. # the search condition type error
  481. search_condition = {
  482. 'metric/accuracy': {
  483. 'lt': 'xxx'
  484. }
  485. }
  486. self.assertRaisesRegex(
  487. LineageSearchConditionParamError,
  488. 'The parameter metric/accuracy is invalid.',
  489. filter_summary_lineage,
  490. LINEAGE_DATA_MANAGER,
  491. None,
  492. search_condition
  493. )
  494. @pytest.mark.level0
  495. @pytest.mark.platform_arm_ascend_training
  496. @pytest.mark.platform_x86_gpu_training
  497. @pytest.mark.platform_x86_ascend_training
  498. @pytest.mark.platform_x86_cpu
  499. @pytest.mark.env_single
  500. def test_filter_summary_lineage_exception_5(self):
  501. """Test the abnormal execution of the filter_summary_lineage interface."""
  502. # gt > lt
  503. search_condition1 = {
  504. 'metric/accuracy': {
  505. 'gt': 1,
  506. 'lt': 0.5
  507. }
  508. }
  509. expect_result = {
  510. 'customized': {},
  511. 'object': [],
  512. 'count': 0
  513. }
  514. partial_res1 = filter_summary_lineage(data_manager=LINEAGE_DATA_MANAGER, search_condition=search_condition1)
  515. assert expect_result == partial_res1
  516. # the (offset + 1) * limit > count
  517. search_condition2 = {
  518. 'loss': {
  519. 'lt': 1
  520. },
  521. 'limit': 1,
  522. 'offset': 4
  523. }
  524. expect_result = {
  525. 'customized': {},
  526. 'object': [],
  527. 'count': 2
  528. }
  529. partial_res2 = filter_summary_lineage(data_manager=LINEAGE_DATA_MANAGER, search_condition=search_condition2)
  530. assert expect_result == partial_res2
  531. @pytest.mark.level0
  532. @pytest.mark.platform_arm_ascend_training
  533. @pytest.mark.platform_x86_gpu_training
  534. @pytest.mark.platform_x86_ascend_training
  535. @pytest.mark.platform_x86_cpu
  536. @pytest.mark.env_single
  537. def test_filter_summary_lineage_exception_6(self):
  538. """Test the abnormal execution of the filter_summary_lineage interface."""
  539. condition_keys = ["summary_dir", "lineage_type", "loss_function", "optimizer", "network", "dataset_mark"]
  540. for condition_key in condition_keys:
  541. # the condition type not supported in summary_dir and lineage_type
  542. search_condition = {
  543. condition_key: {
  544. 'lt': '/xxx'
  545. }
  546. }
  547. self.assertRaisesRegex(
  548. LineageSearchConditionParamError,
  549. f'The parameter {condition_key} is invalid. Its operation should be `eq`, `in` or `not_in`.',
  550. filter_summary_lineage,
  551. LINEAGE_DATA_MANAGER,
  552. None,
  553. search_condition
  554. )
  555. @pytest.mark.level0
  556. @pytest.mark.platform_arm_ascend_training
  557. @pytest.mark.platform_x86_gpu_training
  558. @pytest.mark.platform_x86_ascend_training
  559. @pytest.mark.platform_x86_cpu
  560. @pytest.mark.env_single
  561. def test_filter_summary_lineage_exception_7(self):
  562. """Test the abnormal execution of the filter_summary_lineage interface."""
  563. invalid_lineage_types = ['xxx', None]
  564. for lineage_type in invalid_lineage_types:
  565. search_condition = {
  566. 'lineage_type': {
  567. 'eq': lineage_type
  568. }
  569. }
  570. self.assertRaisesRegex(
  571. LineageSearchConditionParamError,
  572. "The parameter lineage_type is invalid. It should be 'dataset' or 'model'.",
  573. filter_summary_lineage,
  574. LINEAGE_DATA_MANAGER,
  575. None,
  576. search_condition
  577. )
  578. @pytest.mark.level0
  579. @pytest.mark.platform_arm_ascend_training
  580. @pytest.mark.platform_x86_gpu_training
  581. @pytest.mark.platform_x86_ascend_training
  582. @pytest.mark.platform_x86_cpu
  583. @pytest.mark.env_single
  584. def test_filter_summary_lineage_exception_8(self):
  585. """Test the abnormal execution of the filter_summary_lineage interface."""
  586. invalid_sorted_names = ['xxx', 'metric_', 1]
  587. for sorted_name in invalid_sorted_names:
  588. search_condition = {
  589. 'sorted_name': sorted_name
  590. }
  591. self.assertRaisesRegex(
  592. LineageSearchConditionParamError,
  593. 'The sorted_name must be in',
  594. filter_summary_lineage,
  595. LINEAGE_DATA_MANAGER,
  596. None,
  597. search_condition
  598. )
  599. @pytest.mark.level1
  600. @pytest.mark.platform_arm_ascend_training
  601. @pytest.mark.platform_x86_gpu_training
  602. @pytest.mark.platform_x86_ascned_training
  603. @pytest.mark.platform_x86_cpu
  604. @pytest.mark.env_single
  605. def test_get_flattened_lineage(self):
  606. """Test the function of get_flattened_lineage"""
  607. datamanager = data_manager.DataManager(SUMMARY_DIR)
  608. datamanager.register_brief_cache_item_updater(LineageCacheItemUpdater())
  609. datamanager.start_load_data().join()
  610. data = get_flattened_lineage(datamanager)
  611. assert data.get('[U]info') == ['info1']