MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / get_batch

Function get_batch

DeepSpeedExample/pretrain_gpt2.py:57–86  ·  view source on GitHub ↗

Generate a batch

(data_iterator)

Source from the content-addressed store, hash-verified

55
56
57def get_batch(data_iterator):
58 """Generate a batch"""
59 args = get_args()
60 tokenizer = get_tokenizer()
61
62 # Items and their type.
63 keys = ['text']
64 datatype = torch.int64
65
66 # Broadcast data.
67 if data_iterator is not None:
68 data = next(data_iterator)
69 else:
70 data = None
71 data_b = mpu.broadcast_data(keys, data, datatype)
72
73 # Unpack.
74 tokens_ = data_b['text'].long()
75 labels = tokens_[:, 1:].contiguous()
76 tokens = tokens_[:, :-1].contiguous()
77
78 # Get the masks and postition ids.
79 attention_mask, loss_mask, position_ids = get_ltor_masks_and_position_ids(
80 tokens,
81 tokenizer.eod,
82 args.reset_position_ids,
83 args.reset_attention_mask,
84 args.eod_mask_loss)
85
86 return tokens, labels, loss_mask, attention_mask, position_ids
87
88
89def forward_step(data_iterator, model):

Callers 1

forward_stepFunction · 0.70

Calls 3

get_argsFunction · 0.90
get_tokenizerFunction · 0.90

Tested by

no test coverage detected