MCPcopy Index your code
hub / github.com/zai-org/CogView / move_weights

Function move_weights

utils.py:422–437  ·  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

420
421
422def move_weights(our, oai, dst2src=False):
423 """
424 Loads weights from `oai` to `our` via in place copy.
425 `oai` is a huggingface gpt2model, while `our` is one of our models.
426 dst2src=True loads parameters from our models into huggingface's.
427 ^dst2src=True is still untested
428 """
429 # while isinstance(our, (torchDDP, model.distributed.DistributedDataParallel, FP16_Module)):
430 # our=our.module
431 transformer_model = oai.transformer
432 load_weights(transformer_model.ln_f, our.transformer.final_layernorm, dst2src)
433 load_weights(transformer_model.wte, our.word_embeddings, dst2src)
434 load_weights(transformer_model.wpe, our.position_embeddings, dst2src)
435
436 for our_layer, oai_layer in zip(our.transformer.layers, oai.transformer.h):
437 load_transformer_layer(our_layer, oai_layer, dst2src)

Callers

nothing calls this directly

Calls 2

load_weightsFunction · 0.85
load_transformer_layerFunction · 0.85

Tested by

no test coverage detected