MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeedExamples / load_weights

Function load_weights

Megatron-LM/utils.py:361–378  ·  view source on GitHub ↗

Loads weights from src to dst via in place copy. src is a huggingface gpt2model, while dst is one of our models. dst2src=True loads parameters from our models into huggingface's. ^dst2src is still untested

(src, dst, dst2src=False)

Source from the content-addressed store, hash-verified

359
360
361def load_weights(src, dst, dst2src=False):
362 """
363 Loads weights from src to dst via in place copy.
364 src is a huggingface gpt2model, while dst is one of our models.
365 dst2src=True loads parameters from our models into huggingface's.
366 ^dst2src is still untested
367 """
368 conv_layer = 'Conv1D' in str(type(src))
369 for n, p in src.named_parameters():
370 if dst2src:
371 data = dst._parameters[n].data
372 load = p.data
373 else:
374 data = p.data
375 load = dst._parameters[n].data
376 if conv_layer and 'weight' in n:
377 data = data.t().contiguous()
378 load.copy_(data)
379# dst._parameters[n].data.copy_(data)
380
381def load_mlp(our, oai, dst2src=False):

Callers 4

load_mlpFunction · 0.85
load_attentionFunction · 0.85
load_transformer_layerFunction · 0.85
move_weightsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected