MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / test_repr_basic

Function test_repr_basic

imperative/python/test/unit/module/test_module.py:546–595  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

544
545
546def test_repr_basic():
547 # test whether __repr__ can output correct information
548 class ConvModel(Module):
549 def __init__(self):
550 super().__init__()
551 self.conv1 = Conv2d(3, 128, 3, padding=1, bias=False)
552 self.conv2 = Conv2d(3, 128, 3, dilation=2, bias=False)
553 self.bn1 = BatchNorm1d(128)
554 self.bn2 = BatchNorm2d(128)
555 self.pooling = MaxPool2d(kernel_size=2, padding=0)
556 modules = OrderedDict()
557 modules["depthwise"] = Conv2d(256, 256, 3, 1, 0, groups=256, bias=False,)
558 modules["pointwise"] = Conv2d(
559 256, 256, kernel_size=1, stride=1, padding=0, bias=True,
560 )
561 self.submodule1 = Sequential(modules)
562 self.list1 = [Dropout(drop_prob=0.1), [Softmax(axis=100)]]
563 self.tuple1 = (
564 Dropout(drop_prob=0.1),
565 (Softmax(axis=100), Dropout(drop_prob=0.2)),
566 )
567 self.dict1 = {"Dropout": Dropout(drop_prob=0.1)}
568 self.fc1 = Linear(512, 1024)
569
570 def forward(self, inputs):
571 pass
572
573 ground_truth = (
574 "ConvModel(\n"
575 " (conv1): Conv2d(3, 128, kernel_size=(3, 3), padding=(1, 1), bias=False)\n"
576 " (conv2): Conv2d(3, 128, kernel_size=(3, 3), dilation=(2, 2), bias=False)\n"
577 " (bn1): BatchNorm1d(128, eps=1e-05, momentum=0.9, affine=True, track_running_stats=True)\n"
578 " (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.9, affine=True, track_running_stats=True)\n"
579 " (pooling): MaxPool2d(kernel_size=2, stride=2, padding=0)\n"
580 " (submodule1): Sequential(\n"
581 " (depthwise): Conv2d(256, 256, kernel_size=(3, 3), groups=256, bias=False)\n"
582 " (pointwise): Conv2d(256, 256, kernel_size=(1, 1))\n"
583 " )\n"
584 " (list1.0): Dropout(drop_prob=0.1)\n"
585 " (list1.1.0): Softmax(axis=100)\n"
586 " (tuple1.0): Dropout(drop_prob=0.1)\n"
587 " (tuple1.1.0): Softmax(axis=100)\n"
588 " (tuple1.1.1): Dropout(drop_prob=0.2)\n"
589 " (dict1.Dropout): Dropout(drop_prob=0.1)\n"
590 " (fc1): Linear(in_features=512, out_features=1024, bias=True)\n"
591 ")"
592 )
593 net = ConvModel()
594 output = net.__repr__()
595 assert output == ground_truth
596
597
598def test_repr_module_reassign():

Callers

nothing calls this directly

Calls 2

ConvModelClass · 0.85
__repr__Method · 0.45

Tested by

no test coverage detected