| 3 | import json, os |
| 4 | |
| 5 | class NestedModel(BaseModel): |
| 6 | def __init__(self, args, *argv, **kwargs): |
| 7 | super().__init__(args, *argv, **kwargs) |
| 8 | self.net = BertModel(BertModel.get_args( |
| 9 | **args.bert_args |
| 10 | )) |
| 11 | |
| 12 | @classmethod |
| 13 | def add_model_specific_args(cls, parser): |
| 14 | group = parser.add_argument_group('Nested Example', 'Nested Example Configurations') |
| 15 | group.add_argument('--bert_args', type=json.loads, default={}, help='Bert Model Arguments') |
| 16 | return parser |
| 17 | |
| 18 | @BaseMixin.non_conflict |
| 19 | def word_embedding_forward_default(self, input_ids, output_cross_layer, old_impl, **kw_args): |
| 20 | return old_impl(input_ids, **kw_args) + self.net(input_ids, input_ids,input_ids) |
| 21 | |
| 22 | def test_create(): |
| 23 | a = NestedModel(args=NestedModel.get_args(num_layers=2, |
no outgoing calls