MCPcopy Create free account
hub / github.com/TextGeneratorio/text-generator.io / test_gpu_optimizations

Function test_gpu_optimizations

test_gitbase_e2e.py:98–176  ·  view source on GitHub ↗

Test GPU optimizations if available.

()

Source from the content-addressed store, hash-verified

96
97
98def test_gpu_optimizations():
99 """Test GPU optimizations if available."""
100 if not torch.cuda.is_available():
101 print("⚠️ CUDA not available, skipping GPU tests")
102 return
103
104 print("=" * 60)
105 print("TESTING GPU OPTIMIZATIONS")
106 print("=" * 60)
107
108 test_images = create_test_images()
109 sample_image = list(test_images.values())[0]
110
111 # Test different optimization combinations
112 configs = [
113 {"name": "Baseline FP32", "dtype": torch.float32, "use_compile": False, "use_channels_last": False},
114 {"name": "FP16 Optimization", "dtype": torch.float16, "use_compile": False, "use_channels_last": False},
115 {"name": "BF16 Optimization", "dtype": torch.bfloat16, "use_compile": False, "use_channels_last": False},
116 {"name": "Channels Last", "dtype": torch.float16, "use_compile": False, "use_channels_last": True},
117 {"name": "Torch Compile + FP16", "dtype": torch.float16, "use_compile": True, "use_channels_last": False},
118 {"name": "All Optimizations", "dtype": torch.float16, "use_compile": True, "use_channels_last": True},
119 ]
120
121 results = {}
122
123 for config in configs:
124 try:
125 print(f"\n--- Testing {config['name']} ---")
126
127 captioner = GitBaseCaptioner(
128 dtype=config["dtype"],
129 device="cuda",
130 use_compile=config["use_compile"],
131 use_channels_last=config["use_channels_last"],
132 )
133
134 # Warmup run
135 _ = captioner.caption_image_fast(sample_image)
136
137 # Benchmark runs
138 times = []
139 captions = []
140
141 for i in range(5):
142 start_time = time.time()
143 caption = captioner.caption_image_fast(sample_image)
144 elapsed = time.time() - start_time
145 times.append(elapsed)
146 captions.append(caption)
147
148 avg_time = sum(times) / len(times)
149 results[config["name"]] = avg_time
150
151 print(f"Average time: {avg_time:.3f}s")
152 print(f"Sample caption: {captions[0]}")
153 print(f"Caption consistency: {len(set(captions))} unique captions out of 5")
154
155 except Exception as e:

Callers 1

mainFunction · 0.85

Calls 5

caption_image_fastMethod · 0.95
GitBaseCaptionerClass · 0.90
create_test_imagesFunction · 0.85
printFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected