MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / copy_layer_param

Function copy_layer_param

SwissArmyTransformer/examples/vit/transform_param.py:10–21  ·  view source on GitHub ↗

in-place copy from src to dst src and dst should be the same layer type, e.g., both are LayerNorm or both are Linear. Or at least, both have same named_parameters name and shape.

(src, dst)

Source from the content-addressed store, hash-verified

8model = ViTModel(args)
9
10def copy_layer_param(src, dst):
11 """
12 in-place copy from src to dst
13 src and dst should be the same layer type, e.g., both are LayerNorm or both are Linear.
14 Or at least, both have same named_parameters name and shape.
15 """
16 src_dic = dict(src.named_parameters())
17 dst_dic = dict(dst.named_parameters())
18 for k in dst_dic:
19 assert dst_dic[k].data.shape == src_dic[k].data.shape
20 dst_dic[k].data = src_dic[k].data
21 assert (dst_dic[k].data == src_dic[k].data).all()
22
23def copy_from_param(src, dst):
24 assert src.data.shape == dst.data.shape

Callers 2

transform_weightFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected