I’m trying to import a pre-trained PyTorch StyleGAN2 model, however am having some issues.
I get the error:
NotImplementedError: The following operators are not implemented:
[
"profiler::_record_function_exit",
"profiler::_record_function_enter",
"prim::PythonOp",
"aten::square",
"aten::randn",
]
For the aten::randn
, in this thread someone implemented a custom op which keeps the value static:
def randn(inputs, input_types):
return relay.expr.const(
torch.randn(
size=tuple(
int(i.data.asnumpy()) if isinstance(i, relay.Constant) else int(i)
for i in inputs[0]
)
).numpy()
)
I’ve also made a none
function which I think should drop the profiling functions:
def none(inputs, input_types):
return None
I imagine I could maybe make an equivalent for aten::square
, but I wonder if there’s a recommended way of doing it?
compilation should look something like this I reckon:
mod, params = relay.frontend.from_pytorch(
scripted_model,
shape_list,
{
"aten::randn": randn,
"profiler::_record_function_enter": none,
"profiler::_record_function_exit": none,
#"prim::PythonOp": ????,
"aten::square": square,
},
)
I’m aware that prim::PythonOp
is not supported, and am trying to identify what the ops are and if they can be removed.
I’ve got code and instructions available here.