Error saving MONAI pytorch model to ONNX
Labels: module: onnx, triaged

### 🐛 Describe the bug

Hi, I have trained a pytorch RetinaNet3D model using the MONAI framework and would like to serialize it so it can be run with BentoML.  However I get the following error using torch.onnx.export:
```
  Cell In[12], line 1
    torch.onnx.export(detector,               # model being run
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\onnx\utils.py:506 in export
    _export(
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\onnx\utils.py:1548 in _export
    graph, params_dict, torch_out = _model_to_graph(
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\onnx\utils.py:1113 in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\onnx\utils.py:989 in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\onnx\utils.py:893 in _trace_and_get_graph_from_model
    trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph(
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\jit\_trace.py:1268 in _get_trace_graph
    outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\nn\modules\module.py:1501 in _call_impl
    return forward_call(*args, **kwargs)
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\jit\_trace.py:127 in forward
    graph, out = torch._C._create_graph_by_tracing(
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\jit\_trace.py:114 in wrapper
    tuple(x.clone(memory_format=torch.preserve_format) for x in args)
  File ~\AppData\Local\anaconda3\lib\site-packages\torch\jit\_trace.py:114 in <genexpr>
    tuple(x.clone(memory_format=torch.preserve_format) for x in args)
TypeError: MetaTensor.clone() got an unexpected keyword argument 'memory_format'
```

Here is code to reproduce that error, although I can't include the actual model file or example tensor.

```
import torch

from monai.apps.detection.networks.retinanet_detector import RetinaNetDetector
from monai.apps.detection.networks.retinanet_network import RetinaNet
from monai.apps.detection.utils.anchor_utils import AnchorGeneratorWithAnchorShape

anchor_generator = AnchorGeneratorWithAnchorShape(
    feature_map_scales=[2**l for l in range(len([1,2]) + 1)],
    base_anchor_shapes=[[6,8,4],[8,6,5],[10,10,6]]
)


_example_path = r'example_tensor.pt'
_inference_model_path = r'trained_retinanet_model.pt'    
example = torch.load(_example_path, map_location='cpu')

net = torch.jit.load(_inference_model_path, map_location='cpu')

detector = RetinaNetDetector(network=net, anchor_generator=anchor_generator, debug=False)

def __getstate__(self):
    state = self.__dict__.copy(
    state.pop("_thread_local", None)
    state.pop("_metrics_lock", None)
    return state

RetinaNetDetector.__getstate__ = __getstate__
RetinaNet.__getstate__ = __getstate__
torch.jit._script.RecursiveScriptModule.__getstate__ = __getstate__

patch_size = (192,192,96)

detector.set_box_selector_parameters(
    score_thresh=0.02,
    topk_candidates_per_level=1000,
    nms_thresh=0.22,
    detections_per_img=1,
)
detector.set_sliding_window_inferer(
    roi_size=patch_size,
    overlap=0.25,
    sw_batch_size=1,
    mode="gaussian",
    device="cpu",
    # device=device,
)

detector.eval()

torch.onnx.export(detector,
                  example.float().cpu(),
                  "onnx_test.onnx"
                  export_params=True) 
```

What could cause this error?  Thanks!

### Versions

wget does not work on my Windows machine.  I am using the following:

torch=2.0.0
monai=1.1.0