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

Function profile_single_run

tests/quick_profile.py:18–104  ·  view source on GitHub ↗

Profile a single inference run.

()

Source from the content-addressed store, hash-verified

16
17
18def profile_single_run():
19 """Profile a single inference run."""
20 from questions.inference_server.model_cache import ModelCache
21 from questions.models import GenerateParams
22 from questions.text_generator_inference import fast_inference
23
24 model_cache = ModelCache()
25 params = GenerateParams(
26 text="Once upon a time",
27 max_length=20, # Short generation for profiling
28 temperature=0.7,
29 top_p=0.9,
30 top_k=40,
31 number_of_results=1,
32 model="any",
33 )
34
35 # Single warmup
36 print("Warmup...")
37 fast_inference(params, model_cache)
38 if torch.cuda.is_available():
39 torch.cuda.synchronize()
40
41 gc.collect()
42 if torch.cuda.is_available():
43 torch.cuda.empty_cache()
44
45 # Profile single run
46 print("Profiling single inference run...")
47 profiler = cProfile.Profile()
48 profiler.enable()
49
50 result = fast_inference(params, model_cache)
51
52 if torch.cuda.is_available():
53 torch.cuda.synchronize()
54
55 profiler.disable()
56
57 # Print stats
58 stream = io.StringIO()
59 stats = pstats.Stats(profiler, stream=stream)
60 stats.strip_dirs()
61 stats.sort_stats("cumulative")
62
63 print("\n" + "="*60)
64 print("TOP 25 FUNCTIONS BY CUMULATIVE TIME")
65 print("="*60 + "\n")
66
67 stats.print_stats(25)
68 print(stream.getvalue())
69
70 # Component analysis
71 print("\n" + "="*60)
72 print("TIME BY COMPONENT")
73 print("="*60)
74
75 component_times = {

Callers 1

quick_profile.pyFile · 0.85

Calls 4

ModelCacheClass · 0.90
GenerateParamsClass · 0.90
fast_inferenceFunction · 0.90
printFunction · 0.50

Tested by

no test coverage detected