def METHOD_NAME(
    ecr_image,
    sagemaker_session,
    framework_version,
    instance_type,
    model_dir,
    resnet_script,
    resnet_neuron_input,
    resnet_neuron_image_list,
    preprocess_image=False,
    accelerator_type=None,
):
    endpoint_name = sagemaker.utils.unique_name_from_base("sagemaker-pytorch-serving")
    model_data = sagemaker_session.upload_data(
        path=model_dir,
        key_prefix="sagemaker-pytorch-serving/models",
    )
    pytorch = PyTorchModel(
        model_data=model_data,
        role="SageMakerRole",
        entry_point=resnet_script,
        framework_version=framework_version,
        image_uri=ecr_image,
        sagemaker_session=sagemaker_session,
        model_server_workers=2,
        env={
            "AWS_NEURON_VISIBLE_DEVICES": "ALL",
            "NEURON_RT_NUM_CORES": "1",
            "NEURON_RT_LOG_LEVEL": "5",
        },
    )
    with timeout_and_delete_endpoint(endpoint_name, sagemaker_session, minutes=30):
        serializer = IdentitySerializer()
        if preprocess_image:
            serializer = JSONSerializer()
        predictor = pytorch.deploy(
            initial_instance_count=1,
            instance_type=instance_type,
            endpoint_name=endpoint_name,
            serializer=serializer,
            deserializer=BytesDeserializer(),
        )
        with open(resnet_neuron_input, "rb") as f:
            payload = f.read()
        if preprocess_image:
            import io
            import torchvision.transforms as transforms
            from PIL import Image
            data = io.BytesIO(payload)
            input_image = Image.open(data).convert("RGB")
            preprocess = transforms.Compose(
                [
                    transforms.Resize(255),
                    transforms.CenterCrop(224),
                    transforms.ToTensor(),
                    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
                ]
            )
            input_tensor = preprocess(input_image)
            input_batch = input_tensor.unsqueeze(0)
            payload = input_batch.tolist()
        output = predictor.predict(data=payload)
        print(output)
        result = json.loads(output.decode())
        print(result)
        # Load names for ImageNet classes
        object_categories = {}
        if accelerator_type == "neuronx":
            with open(resnet_neuron_image_list, "r") as f:
                object_categories = json.load(f)
            assert "cat" in object_categories[str(np.argmax(result))][1]
            return
        with open(resnet_neuron_image_list, "r") as f:
            for line in f:
                key, val = line.strip().split(":")
                object_categories[key] = val
        assert "cat" in object_categories[str(np.argmax(result))]