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

Function test_memory_usage

test_gitbase_e2e.py:323–361  ·  view source on GitHub ↗

Test memory usage and cleanup.

()

Source from the content-addressed store, hash-verified

321
322
323def test_memory_usage():
324 """Test memory usage and cleanup."""
325 if not torch.cuda.is_available():
326 print("⚠️ CUDA not available, skipping memory tests")
327 return
328
329 print("=" * 60)
330 print("TESTING MEMORY USAGE")
331 print("=" * 60)
332
333 test_images = create_test_images()
334 sample_image = list(test_images.values())[0]
335
336 # Clear cache
337 torch.cuda.empty_cache()
338 initial_memory = torch.cuda.memory_allocated()
339
340 print(f"Initial GPU memory: {initial_memory / 1024**2:.1f} MB")
341
342 # Create captioner and run inference
343 captioner = GitBaseCaptioner(dtype=torch.float16, device="cuda", use_compile=False, use_channels_last=True)
344
345 # Load model
346 captioner.load()
347 after_load_memory = torch.cuda.memory_allocated()
348
349 print(f"Memory after model load: {after_load_memory / 1024**2:.1f} MB")
350 print(f"Model memory usage: {(after_load_memory - initial_memory) / 1024**2:.1f} MB")
351
352 # Run inference
353 for i in range(10):
354 captioner.caption_image_fast(sample_image)
355 if i == 0:
356 after_first_inference = torch.cuda.memory_allocated()
357 print(f"Memory after first inference: {after_first_inference / 1024**2:.1f} MB")
358
359 final_memory = torch.cuda.memory_allocated()
360 print(f"Final memory: {final_memory / 1024**2:.1f} MB")
361 print(f"Memory growth during inference: {(final_memory - after_first_inference) / 1024**2:.1f} MB")
362
363
364def main():

Callers 1

mainFunction · 0.85

Calls 5

loadMethod · 0.95
caption_image_fastMethod · 0.95
GitBaseCaptionerClass · 0.90
create_test_imagesFunction · 0.85
printFunction · 0.50

Tested by

no test coverage detected