MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / Timer

Class Timer

tests/test_functional.py:66–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65
66class Timer:
67 def __init__(self):
68 self.starts = {}
69 self.ends = {}
70 self.agg = {}
71
72 def tick(self, name="default"):
73 if name not in self.starts:
74 self.starts[name] = torch.cuda.Event(enable_timing=True)
75 self.ends[name] = torch.cuda.Event(enable_timing=True)
76 self.starts[name].record()
77 else:
78 ms = self.tock(name, evict=True, print_ms=False)
79
80 def tock(self, name="default", evict=True, print_ms=True):
81 if name in self.ends:
82 self.ends[name].record()
83 torch.cuda.synchronize()
84 ms = self.starts[name].elapsed_time(self.ends[name])
85 if name not in self.agg:
86 self.agg[name] = 0.0
87 self.agg[name] += ms
88 if evict:
89 self.starts.pop(name)
90 self.ends.pop(name)
91
92 if print_ms and name in self.agg:
93 print(f"{name} took: {self.agg[name] / 1000.0:.5f}s")
94
95 return self.agg[name]
96
97 def reset(self):
98 self.starts = {}
99 self.ends = {}
100 self.agg = {}
101 print("Resetting benchmark data")
102
103
104class Test8BitBlockwiseQuantizeFunctional:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected