MCPcopy Create free account
hub / github.com/OpenSparseLLMs/MoM / benchmark_fwd_bwd

Function benchmark_fwd_bwd

benchmarks/ops/benchmark.py:117–151  ·  view source on GitHub ↗

Use Pytorch Benchmark on the forward+backward pass of an arbitrary function.

(
    fn,
    *inputs,
    grad=None,
    repeats=10,
    desc="",
    verbose=True,
    amp=False,
    amp_dtype=torch.float16,
    **kwinputs,
)

Source from the content-addressed store, hash-verified

115
116
117def benchmark_fwd_bwd(
118 fn,
119 *inputs,
120 grad=None,
121 repeats=10,
122 desc="",
123 verbose=True,
124 amp=False,
125 amp_dtype=torch.float16,
126 **kwinputs,
127):
128 """Use Pytorch Benchmark on the forward+backward pass of an arbitrary function."""
129 return (
130 benchmark_forward(
131 fn,
132 *inputs,
133 repeats=repeats,
134 desc=desc,
135 verbose=verbose,
136 amp=amp,
137 amp_dtype=amp_dtype,
138 **kwinputs,
139 ),
140 benchmark_backward(
141 fn,
142 *inputs,
143 grad=grad,
144 repeats=repeats,
145 desc=desc,
146 verbose=verbose,
147 amp=amp,
148 amp_dtype=amp_dtype,
149 **kwinputs,
150 ),
151 )
152
153
154def benchmark_all(

Callers

nothing calls this directly

Calls 2

benchmark_forwardFunction · 0.85
benchmark_backwardFunction · 0.85

Tested by

no test coverage detected