MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / model_provider

Function model_provider

codegeex/megatron/tools/finetune_codegeex.py:19–85  ·  view source on GitHub ↗

Build the model.

(pre_process=True, post_process=True)

Source from the content-addressed store, hash-verified

17
18
19def model_provider(pre_process=True, post_process=True):
20 """Build the model."""
21
22 print_rank_0("building GPT model ...")
23 see_memory_usage(f"Before Building Model", force=True)
24
25 args = get_args()
26 with deepspeed.zero.Init(
27 data_parallel_group=mpu.get_data_parallel_group(),
28 remote_device=None if args.remote_device == "none" else args.remote_device,
29 config_dict_or_path=args.deepspeed_config,
30 enabled=args.zero_stage == 3,
31 mpu=mpu,
32 ):
33 if args.deepspeed and not args.no_pipeline_parallel:
34 model = CodeGeeXModelPipe(num_tokentypes=0, parallel_output=True)
35 # This is a hack to give us a reference to get_batch_pipe from within training.py
36 # We need to call model.set_batch_fn after deepspeed.initialize
37 model._megatron_batch_fn = get_batch_pipe
38
39 # Predompute the attention mask and store it in args. This avoids having to
40 # pipeline it as an activation during training. The mask is constant, and thus
41 # we can reuse it.
42 attention_mask = torch.tril(
43 torch.ones(
44 (1, args.seq_length, args.seq_length),
45 device=torch.cuda.current_device(),
46 )
47 ).view(1, 1, args.seq_length, args.seq_length)
48
49 # Convert attention mask to binary:
50 attention_mask = attention_mask < 0.5
51 if args.fp16:
52 attention_mask = attention_mask.half()
53 elif args.bf16:
54 attention_mask = attention_mask.bfloat16()
55
56 # Attention mask must be bool.
57 args.attn_mask = attention_mask.to(torch.bool)
58
59 else:
60 model = CodeGeeXModel(
61 num_tokentypes=0,
62 parallel_output=True,
63 )
64
65 if args.load_state is not None:
66 timers = get_timers()
67 print_rank_0("Loading warmstarting model states ...")
68 timers("load-model-states").start()
69 mp_rank = mpu.get_tensor_model_parallel_rank()
70 if os.path.isdir(args.load_state):
71 model_path = os.path.join(
72 args.load_state, "mp_rank_{:02d}_model_states.pt".format(mp_rank)
73 )
74 else:
75 model_path = args.load_state
76 print_rank_0(f"Loading model from {model_path} ...")

Callers

nothing calls this directly

Calls 9

load_state_dictMethod · 0.95
print_rank_0Function · 0.90
get_argsFunction · 0.90
CodeGeeXModelClass · 0.90
get_timersFunction · 0.90
CodeGeeXModelPipeClass · 0.85
startMethod · 0.80
stopMethod · 0.80
logMethod · 0.80

Tested by

no test coverage detected