MCPcopy Create free account
hub / github.com/CompVis/zigma / flops

Function flops

model_zigma.py:1183–1211  ·  view source on GitHub ↗
(model, shape=(3, 32, 32))

Source from the content-addressed store, hash-verified

1181
1182
1183def flops(model, shape=(3, 32, 32)):
1184 from fvcore.nn import FlopCountAnalysis, flop_count_str, flop_count, parameter_count
1185
1186 # shape = self.__input_shape__[1:]
1187 supported_ops = {
1188 "aten::silu": None, # as relu is in _IGNORED_OPS
1189 "aten::neg": None, # as relu is in _IGNORED_OPS
1190 "aten::exp": None, # as relu is in _IGNORED_OPS
1191 "aten::flip": None, # as permute is in _IGNORED_OPS
1192 # "prim::PythonOp.CrossScan": None,
1193 # "prim::PythonOp.CrossMerge": None,
1194 "prim::PythonOp.SelectiveScanFn": partial(
1195 selective_scan_flop_jit, flops_fn=flops_selective_scan_fn
1196 ),
1197 }
1198
1199 model = copy.deepcopy(model)
1200 model.cuda().eval()
1201
1202 input = torch.randn((1, *shape), device=next(model.parameters()).device)
1203 timestep = torch.rand((1), device=next(model.parameters()).device)
1204 params = parameter_count(model)[""]
1205 Gflops, unsupported = flop_count(
1206 model=model, inputs=(input, timestep), supported_ops=supported_ops
1207 )
1208
1209 del model, input
1210 print(f"params {params} GFLOPs {sum(Gflops.values())}")
1211 return sum(Gflops.values()) * 1e9
1212
1213
1214if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected