MCPcopy Create free account
hub / github.com/OpenSparseLLMs/Linear-MoE / get_batch

Function get_batch

examples/linear_llama3/pretrain_llama.py:160–184  ·  view source on GitHub ↗

Generate a batch.

(data_iterator)

Source from the content-addressed store, hash-verified

158
159
160def get_batch(data_iterator):
161 """Generate a batch."""
162
163 # TODO: this is pretty hacky, find a better way
164 if (not mpu.is_pipeline_first_stage()) and (not mpu.is_pipeline_last_stage()):
165 return None, None, None, None, None
166
167 args = get_args()
168
169 if "-Raw" in args.dataset:
170 # get batches based on the TP rank you are on
171 batch = get_batch_on_this_tp_rank_original(data_iterator)
172 # slice batch along sequence dimension for context parallelism
173 batch = get_batch_on_this_cp_rank(batch)
174
175 elif "-Idxmap" in args.dataset:
176 # get batches based on the TP rank you are on
177 batch = get_batch_on_this_tp_rank(data_iterator)
178 # slice batch along sequence dimension for context parallelism
179 batch = get_batch_on_this_cp_rank(batch)
180
181 else:
182 raise ValueError("please set correct --dataset ")
183
184 return batch.values()
185
186def loss_func(loss_mask: torch.Tensor, output_tensor: torch.Tensor):
187 """Loss function.

Callers 1

forward_stepFunction · 0.70

Calls 2

get_argsFunction · 0.50

Tested by

no test coverage detected