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

Function get_batch

codegeex/megatron/tools/pretrain_codegeex.py:89–120  ·  view source on GitHub ↗

Generate a batch

(data_iterator)

Source from the content-addressed store, hash-verified

87
88
89def get_batch(data_iterator):
90 """Generate a batch"""
91 args = get_args()
92 tokenizer = get_tokenizer()
93
94 # Items and their type.
95 keys = ["input_ids"]
96 datatype = torch.int64
97
98 # Broadcast data.
99 if data_iterator is not None:
100 data = next(data_iterator)
101 else:
102 data = None
103
104 data_b = mpu.broadcast_data(keys, data, datatype)
105
106 # Unpack.
107 tokens_ = data_b["input_ids"].long()
108 labels = tokens_[:, 1:].contiguous()
109 tokens = tokens_[:, :-1].contiguous()
110
111 # Get the masks and postition ids.
112 attention_mask, loss_mask, position_ids = get_ltor_masks_and_position_ids(
113 tokens,
114 tokenizer.eod,
115 args.reset_position_ids,
116 args.reset_attention_mask,
117 args.eod_mask_loss,
118 )
119
120 return tokens, labels, loss_mask, attention_mask, position_ids
121
122
123def get_batch_pipe(data):

Callers 1

forward_stepFunction · 0.70

Calls 3

get_argsFunction · 0.90
get_tokenizerFunction · 0.90

Tested by

no test coverage detected