Create create_experiments
Browse files- create_experiments +71 -0
create_experiments
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import csv
|
| 3 |
+
|
| 4 |
+
def generate_ratios(max_layers, max_width):
|
| 5 |
+
ratios = []
|
| 6 |
+
for i in range(1, 9): # 1/8 steps from 1:1 to 1:3 and vice versa
|
| 7 |
+
ratio = i / 8
|
| 8 |
+
if ratio <= 3: # Ensure the ratio is not greater than 3
|
| 9 |
+
ratios.append(ratio)
|
| 10 |
+
return ratios
|
| 11 |
+
|
| 12 |
+
def generate_experiments(max_layers, max_width):
|
| 13 |
+
experiments = []
|
| 14 |
+
ratios = generate_ratios(max_layers, max_width)
|
| 15 |
+
|
| 16 |
+
for ratio in ratios:
|
| 17 |
+
for layers in range(1, max_layers + 1):
|
| 18 |
+
width = int(max_width * ratio)
|
| 19 |
+
experiments.append((layers, width))
|
| 20 |
+
|
| 21 |
+
return experiments
|
| 22 |
+
|
| 23 |
+
def estimate_vram(layer_count, width, input_size, output_size):
|
| 24 |
+
# Calculate the number of parameters
|
| 25 |
+
# Each layer has (input_size * width) + width parameters (weights + biases)
|
| 26 |
+
# The last layer has (width * output_size) + output_size parameters
|
| 27 |
+
param_count = 0
|
| 28 |
+
for i in range(layer_count):
|
| 29 |
+
if i == 0:
|
| 30 |
+
param_count += (input_size * width) + width
|
| 31 |
+
else:
|
| 32 |
+
param_count += (width * width) + width
|
| 33 |
+
param_count += (width * output_size) + output_size
|
| 34 |
+
|
| 35 |
+
# Estimate the VRAM usage
|
| 36 |
+
# Parameters: 4 bytes per parameter (FP32)
|
| 37 |
+
# Activations: Assume the size of the activations is the same as the input size
|
| 38 |
+
vram_usage = param_count * 4 + input_size * 4
|
| 39 |
+
|
| 40 |
+
return vram_usage
|
| 41 |
+
|
| 42 |
+
def write_csv(experiments, filename):
|
| 43 |
+
with open(filename, 'w', newline='') as csvfile:
|
| 44 |
+
writer = csv.writer(csvfile)
|
| 45 |
+
writer.writerow(['layer_count', 'width', 'vram_usage'])
|
| 46 |
+
for experiment in experiments:
|
| 47 |
+
writer.writerow(experiment)
|
| 48 |
+
|
| 49 |
+
def main():
|
| 50 |
+
parser = argparse.ArgumentParser(description='Generate a CSV file with a variety of layer counts and widths.')
|
| 51 |
+
parser.add_argument('--max_layers', type=int, default=4, help='Maximum number of layers (default: 4)')
|
| 52 |
+
parser.add_argument('--max_width', type=int, default=2048, help='Maximum width (default: 2048)')
|
| 53 |
+
parser.add_argument('--output_file', type=str, default='experiments.csv', help='Output CSV file (default: experiments.csv)')
|
| 54 |
+
parser.add_argument('--input_size', type=int, default=224*224*3, help='Input size (default: 224*224*3)')
|
| 55 |
+
parser.add_argument('--output_size', type=int, default=10, help='Output size (default: 10)')
|
| 56 |
+
args = parser.parse_args()
|
| 57 |
+
|
| 58 |
+
experiments = generate_experiments(args.max_layers, args.max_width)
|
| 59 |
+
experiments_with_vram = []
|
| 60 |
+
|
| 61 |
+
for experiment in experiments:
|
| 62 |
+
layer_count, width = experiment
|
| 63 |
+
vram_usage = estimate_vram(layer_count, width, args.input_size, args.output_size)
|
| 64 |
+
experiments_with_vram.append((layer_count, width, vram_usage))
|
| 65 |
+
print(f'Layer Count: {layer_count}, Width: {width}, Estimated VRAM Usage: {vram_usage} bytes')
|
| 66 |
+
|
| 67 |
+
write_csv(experiments_with_vram, args.output_file)
|
| 68 |
+
print(f'Generated {len(experiments_with_vram)} experiments and saved to {args.output_file}')
|
| 69 |
+
|
| 70 |
+
if __name__ == '__main__':
|
| 71 |
+
main()
|