()
| 325 | |
| 326 | |
| 327 | def test_query(): |
| 328 | class Model(M.Module): |
| 329 | def __init__(self): |
| 330 | super().__init__() |
| 331 | self.conv1 = M.Conv2d(3, 32, 3) |
| 332 | self.conv2 = M.Conv2d(32, 32, 3) |
| 333 | self.conv3 = M.Conv2d(32, 32, 3) |
| 334 | |
| 335 | def forward(self, data): |
| 336 | x = self.conv1(data) |
| 337 | x = self.conv2(x) |
| 338 | x = self.conv3(x) |
| 339 | return x |
| 340 | |
| 341 | n = Model() |
| 342 | |
| 343 | @trace(symbolic=True, capture_as_const=True) |
| 344 | def fwd(data): |
| 345 | return n(data) |
| 346 | |
| 347 | fwd(Tensor(np.random.random((1, 3, 224, 224)))) |
| 348 | orig_model = io.BytesIO() |
| 349 | fwd.dump( |
| 350 | orig_model, |
| 351 | arg_names=["data"], |
| 352 | output_names="o", |
| 353 | keep_opr_name=True, |
| 354 | keep_var_name=True, |
| 355 | optimize_for_inference=False, |
| 356 | ) |
| 357 | orig_model.seek(0) |
| 358 | |
| 359 | graph = Net.load(orig_model) |
| 360 | |
| 361 | r = graph.data_providers_filter.as_count() |
| 362 | assert r == 1 |
| 363 | |
| 364 | opr = graph.get_opr_by_type(Host2DeviceCopy) |
| 365 | assert isinstance(opr, Host2DeviceCopy) |
| 366 | |
| 367 | r1 = graph.params_filter.as_count() |
| 368 | assert r1 == 6 |
| 369 | |
| 370 | r2 = graph.opr_filter.type(N.ConvolutionForward).as_count() |
| 371 | assert r2 == 3 |
| 372 | |
| 373 | r3 = graph.opr_filter.not_type(N.ConvolutionForward).as_count() |
| 374 | assert r3 == len(graph.all_oprs) - r2 |
| 375 | |
| 376 | var = graph.var_filter.name("data").as_unique() |
| 377 | r4 = graph.opr_filter.has_input(var).as_count() |
| 378 | assert r4 == 1 |
| 379 | |
| 380 | r5 = graph.opr_filter.name("data").as_count() |
| 381 | assert r5 == 1 |
| 382 | |
| 383 | opr = graph.get_opr_by_name("data") |
| 384 | assert isinstance(opr, Host2DeviceCopy) |
nothing calls this directly
no test coverage detected