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)
| 23 | model = MAE(args, layernorm_epsilon=1e-6) |
| 24 | |
| 25 | def copy_layer_param(src, dst): |
| 26 | """ |
| 27 | in-place copy from src to dst |
| 28 | src and dst should be the same layer type, e.g., both are LayerNorm or both are Linear. |
| 29 | Or at least, both have same named_parameters name and shape. |
| 30 | """ |
| 31 | src_dic = dict(src.named_parameters()) |
| 32 | dst_dic = dict(dst.named_parameters()) |
| 33 | for k in dst_dic: |
| 34 | assert dst_dic[k].data.shape == src_dic[k].data.shape |
| 35 | dst_dic[k].data = src_dic[k].data |
| 36 | assert (dst_dic[k].data == src_dic[k].data).all() |
| 37 | |
| 38 | def copy_from_param(src, dst): |
| 39 | assert src.data.shape == dst.data.shape |
no outgoing calls
no test coverage detected