Is it possible to add `amax` operator in an old version(1.10.0) pytorch?

When I use torch.onnx.export to export my model to an onnx, it shows error,

Exporting the operator amax to Exporting the operator amax to ONNX opset version 11 is not supported.

I know when pip install a new version of torch(1.12.0) it can be solves this problem,
However, due to some reason, my torch version must be fixed(detectron2 0.6 can only worked in torch 1.10), so is it possible to only add part of code in old version torch to make it work?

In detail, I found this part in new ver pytorch

@symbolic_helper.parse_args("v", "is", "i")
def amax(g: jit_utils.GraphContext, self, dim, keepdim):
    return g.op("ReduceMax", self, axes_i=dim, keepdims_i=keepdim)

I was wondering if I can copy/paste corrsponding code into old version…

You can certainly try to copy/paste the code into the locally installed PyTorch source files given in the posted path but would need to make sure all needed code is available.
However, in case you need to add C++ code, you would need to rebuild PyTorch.

Hi ptrblck, thanks for your reply again, now the problem is how and where to add/copy the new operator to old version…

Based on your previous post I assumed you have already found the missing code. To add it, you could check print(torch.__path__) and manipulate the corresponding files directly. However, as mentioned before, backporting a new feature into an old release might need more code changes than just adding the new method so you could also check the corresponding PR to see where manipulations were done.