AlienChen commited on
Commit
f084507
·
verified ·
1 Parent(s): ac43a56

Update muppit/calculate_steps.py

Browse files
Files changed (1) hide show
  1. muppit/calculate_steps.py +72 -0
muppit/calculate_steps.py CHANGED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+
3
+
4
+ # def calculate_steps_per_epoch(total_samples, batch_size_per_gpu, num_gpus, scheduling):
5
+ # # Calculate total batch size across all GPUs
6
+ # total_batch_size = batch_size_per_gpu * num_gpus
7
+ #
8
+ # # Calculate total batches per epoch
9
+ # batches_per_epoch = math.ceil(total_samples / total_batch_size)
10
+ #
11
+ # steps_per_epoch = []
12
+ # current_accumulation_factor = 1 # Default accumulation factor
13
+ #
14
+ # for epoch in range(max(scheduling.keys()) + 1):
15
+ # # Update accumulation factor if it's defined for the current epoch
16
+ # if epoch in scheduling:
17
+ # current_accumulation_factor = scheduling[epoch]
18
+ #
19
+ # effective_steps = math.ceil(batches_per_epoch / current_accumulation_factor)
20
+ # steps_per_epoch.append(effective_steps)
21
+ #
22
+ # return steps_per_epoch
23
+
24
+ def calculate_total_steps(total_samples, batch_size, num_gpus, accumulation_schedule, max_epochs):
25
+ total_steps = 0
26
+
27
+ for epoch in range(max_epochs):
28
+ # Determine the accumulation steps for the current epoch
29
+ for start_epoch, steps in accumulation_schedule.items():
30
+ if start_epoch > epoch:
31
+ break
32
+ accumulation_steps = steps
33
+
34
+ effective_batch_size = batch_size * num_gpus * accumulation_steps
35
+ steps_per_epoch = (total_samples + effective_batch_size - 1) // effective_batch_size
36
+
37
+ total_steps += steps_per_epoch
38
+ print(f'Epoch {epoch}: {steps_per_epoch} steps (accumulation_steps={accumulation_steps})')
39
+
40
+ return total_steps
41
+
42
+
43
+ total_samples = 4804 # Replace with the actual number of samples in your dataset
44
+ batch_size = 32
45
+ num_gpus = 1
46
+ accumulation_schedule = {0: 4, 3: 3, 10: 2}
47
+ max_epochs = 20
48
+
49
+ total_steps = calculate_total_steps(total_samples, batch_size, num_gpus, accumulation_schedule, max_epochs)
50
+ print(f"Total Steps: {total_steps}")
51
+
52
+ # total_samples = 309503 # Replace with the actual number of samples in your dataset
53
+ # batch_size = 32
54
+ # num_gpus = 7
55
+ # accumulation_schedule = {0: 4, 2: 2, 7: 1}
56
+ # max_epochs = 10
57
+ #
58
+ # total_steps = calculate_total_steps(total_samples, batch_size, num_gpus, accumulation_schedule, max_epochs)
59
+ # print(f"Total Steps: {total_steps}")
60
+
61
+ #
62
+ # # Example usage
63
+ # total_samples = 309503
64
+ # batch_size_per_gpu = 16
65
+ # num_gpus = 7
66
+ # scheduling = {0: 4, 5: 3, 10: 2, 13: 1}
67
+ #
68
+ # steps_per_epoch = calculate_steps_per_epoch(total_samples, batch_size_per_gpu, num_gpus, scheduling)
69
+ # for epoch, steps in enumerate(steps_per_epoch):
70
+ # print(f"Epoch {epoch}: {steps} steps")
71
+ #
72
+ # print(f"Total steps: {sum(steps_per_epoch)}")