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

Function move_weights

Megatron-LM/utils.py:395–410  ·  view source on GitHub ↗

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

(our, oai, dst2src=False)

Source from the content-addressed store, hash-verified

393 load_attention(our.attention, oai.attn, dst2src)
394
395def move_weights(our, oai, dst2src=False):
396 """
397 Loads weights from `oai` to `our` via in place copy.
398 `oai` is a huggingface gpt2model, while `our` is one of our models.
399 dst2src=True loads parameters from our models into huggingface's.
400 ^dst2src=True is still untested
401 """
402# while isinstance(our, (torchDDP, model.distributed.DistributedDataParallel, FP16_Module)):
403# our=our.module
404 transformer_model = oai.transformer
405 load_weights(transformer_model.ln_f, our.transformer.final_layernorm, dst2src)
406 load_weights(transformer_model.wte, our.word_embeddings, dst2src)
407 load_weights(transformer_model.wpe, our.position_embeddings, dst2src)
408
409 for our_layer, oai_layer in zip(our.transformer.layers, oai.transformer.h):
410 load_transformer_layer(our_layer, oai_layer, dst2src)

Callers 1

mainFunction · 0.90

Calls 2

load_weightsFunction · 0.85
load_transformer_layerFunction · 0.85

Tested by

no test coverage detected