MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / get_batch

Function get_batch

SwissArmyTransformer/examples/clip/finetune_clip_cifar10.py:15–47  ·  view source on GitHub ↗
(data_iterator, args, timers)

Source from the content-addressed store, hash-verified

13from sat.training.deepspeed_training import training_main
14
15def get_batch(data_iterator, args, timers):
16 # Items and their type.
17
18 datatype = torch.int64
19
20 # Broadcast data.
21 timers('data loader').start()
22 if data_iterator is not None:
23 data = next(data_iterator)
24 else:
25 data = None
26 image_data = {"image":data[0]}
27 label_data = {"label":data[1]}
28 timers('data loader').stop()
29 image_data = mpu.broadcast_data(["image"], image_data, torch.float32)
30 label_data = mpu.broadcast_data(["label"], label_data, torch.int64)
31
32 # Unpack.
33 label_data = label_data['label'].long()
34 image_data = image_data['image']
35 batch_size = label_data.size()[0]
36 seq_length = args.pre_len + (args.image_size[0]//args.patch_size)*(args.image_size[1]//args.patch_size) + args.post_len
37 position_ids = torch.zeros(seq_length, device=image_data.device, dtype=torch.long)
38 torch.arange(0, seq_length, out=position_ids[:seq_length])
39 position_ids = position_ids.unsqueeze(0).expand([batch_size, -1])
40 attention_mask = torch.ones((1, 1), device=image_data.device)
41
42 tokens = torch.zeros((batch_size, 1), device=image_data.device, dtype=torch.long)
43 # Convert
44 if args.fp16:
45 attention_mask = attention_mask.half()
46 image_data = image_data.half()
47 return tokens, image_data, label_data, attention_mask, position_ids
48
49
50def forward_step(data_iterator, model, args, timers):

Callers 1

forward_stepFunction · 0.70

Calls 2

startMethod · 0.80
stopMethod · 0.80

Tested by

no test coverage detected