---
source: src/patch/parse.rs
expression: patches
input_file: src/patch/test-data/pure-renames.patch
---
Ok(
    [
        Patch {
            original: Some(
                Filename(
                    "examples/benchmark_onnx.py",
                ),
            ),
            modified: Some(
                Filename(
                    "examples/benchmark_onnx.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    new_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "import sys, time\n",
                        ),
                        Context(
                            "from tinygrad import TinyJit, GlobalCounters, fetch, getenv\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "from extra.onnx_helpers import get_example_inputs, validate\n",
                        ),
                        Context(
                            "\n",
                        ),
                        Context(
                            "def load_onnx_model(onnx_file):\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "examples/compile_tensorflow.py",
                ),
            ),
            modified: Some(
                Filename(
                    "examples/compile_tensorflow.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 8,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 8,
                        len: 7,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "import subprocess\n",
                        ),
                        Context(
                            "import tensorflow as tf\n",
                        ),
                        Context(
                            "import tf2onnx\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "from tinygrad.tensor import Tensor\n",
                        ),
                        Context(
                            "from tinygrad.helpers import to_mv\n",
                        ),
                        Context(
                            "from extra.export_model import export_model_clang, compile_net, jit_model\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "examples/openpilot/compile3.py",
                ),
            ),
            modified: Some(
                Filename(
                    "examples/openpilot/compile3.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 10,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 10,
                        len: 7,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "from tinygrad.engine.realize import CompiledRunner\n",
                        ),
                        Context(
                            "\n",
                        ),
                        Context(
                            "import onnx\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "\n",
                        ),
                        Context(
                            "OPENPILOT_MODEL = sys.argv[1] if len(sys.argv) > 1 else \"https://github.com/commaai/openpilot/raw/v0.9.7/selfdrive/modeld/models/supercombo.onnx\"\n",
                        ),
                        Context(
                            "OUTPUT = sys.argv[2] if len(sys.argv) > 2 else \"/tmp/openpilot.pkl\"\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "examples/openpilot/compile4.py",
                ),
            ),
            modified: Some(
                Filename(
                    "examples/openpilot/compile4.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 1,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 1,
                        len: 7,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "import sys\n",
                        ),
                        Context(
                            "from tinygrad import Tensor, fetch, GlobalCounters, dtypes\n",
                        ),
                        Context(
                            "from tinygrad.uop.ops import UOp\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "from tinygrad.schedule.kernelize import get_kernelize_map\n",
                        ),
                        Context(
                            "from tinygrad.schedule.rangeify import get_rangeify_map\n",
                        ),
                        Context(
                            "from tinygrad.helpers import RANGEIFY\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "examples/other_mnist/beautiful_mnist_torch.py",
                ),
            ),
            modified: Some(
                Filename(
                    "examples/other_mnist/beautiful_mnist_torch.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 27,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 27,
                        len: 7,
                    },
                    function_context: Some(
                        "def forward(self, x):\n",
                    ),
                    lines: [
                        Context(
                            "\n",
                        ),
                        Context(
                            "if __name__ == \"__main__\":\n",
                        ),
                        Context(
                            "  if getenv(\"TINY_BACKEND\"):\n",
                        ),
                        Delete(
                            "    import tinygrad.frontend.torch  # noqa: F401\n",
                        ),
                        Insert(
                            "    import tinygrad.nn.torch  # noqa: F401\n",
                        ),
                        Context(
                            "    device = torch.device(\"tiny\")\n",
                        ),
                        Context(
                            "  else:\n",
                        ),
                        Context(
                            "    device = torch.device({\"METAL\":\"mps\",\"NV\":\"cuda\"}.get(Device.DEFAULT, \"cpu\"))\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "examples/yolov8-onnx.py",
                ),
            ),
            modified: Some(
                Filename(
                    "examples/yolov8-onnx.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 2,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 2,
                        len: 7,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "import os\n",
                        ),
                        Context(
                            "from ultralytics import YOLO\n",
                        ),
                        Context(
                            "from pathlib import Path\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "from extra.onnx_helpers import get_example_inputs\n",
                        ),
                        Context(
                            "\n",
                        ),
                        Context(
                            "os.chdir(\"/tmp\")\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "extra/huggingface_onnx/run_models.py",
                ),
            ),
            modified: Some(
                Filename(
                    "extra/huggingface_onnx/run_models.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    new_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "import onnx, yaml, tempfile, time, argparse, json\n",
                        ),
                        Context(
                            "from pathlib import Path\n",
                        ),
                        Context(
                            "from typing import Any\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "from extra.onnx_helpers import validate, get_example_inputs\n",
                        ),
                        Context(
                            "from extra.huggingface_onnx.huggingface_manager import DOWNLOADS_DIR, snapshot_download_with_retry\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "extra/onnx_helpers.py",
                ),
            ),
            modified: Some(
                Filename(
                    "extra/onnx_helpers.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 1,
                        len: 5,
                    },
                    new_range: HunkRange {
                        start: 1,
                        len: 5,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "from tinygrad import Tensor\n",
                        ),
                        Context(
                            "from tinygrad.tensor import _to_np_dtype\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner, OnnxValue\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner, OnnxValue\n",
                        ),
                        Context(
                            "import numpy as np\n",
                        ),
                        Context(
                            "import onnxruntime as ort\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "extra/torch_backend/test_inplace.py",
                ),
            ),
            modified: Some(
                Filename(
                    "extra/torch_backend/test_inplace.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 1,
                        len: 5,
                    },
                    new_range: HunkRange {
                        start: 1,
                        len: 5,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "import unittest\n",
                        ),
                        Context(
                            "import torch\n",
                        ),
                        Delete(
                            "import tinygrad.frontend.torch\n",
                        ),
                        Insert(
                            "import tinygrad.nn.torch\n",
                        ),
                        Context(
                            "torch.set_default_device(\"tiny\")\n",
                        ),
                        Context(
                            "import numpy as np\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "extra/torch_backend/test_multigpu.py",
                ),
            ),
            modified: Some(
                Filename(
                    "extra/torch_backend/test_multigpu.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    new_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "import unittest\n",
                        ),
                        Context(
                            "from tinygrad.helpers import getenv\n",
                        ),
                        Context(
                            "import torch\n",
                        ),
                        Delete(
                            "import tinygrad.frontend.torch\n",
                        ),
                        Insert(
                            "import tinygrad.nn.torch\n",
                        ),
                        Context(
                            "torch.set_default_device(\"tiny\")\n",
                        ),
                        Context(
                            "import numpy as np\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "setup.py",
                ),
            ),
            modified: Some(
                Filename(
                    "setup.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 31,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 31,
                        len: 6,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "        'tinygrad.codegen.opt',\n",
                        ),
                        Context(
                            "        'tinygrad.codegen.late',\n",
                        ),
                        Context(
                            "        'tinygrad.engine',\n",
                        ),
                        Delete(
                            "        'tinygrad.frontend',\n",
                        ),
                        Context(
                            "        'tinygrad.nn',\n",
                        ),
                        Context(
                            "        'tinygrad.renderer',\n",
                        ),
                        Context(
                            "        'tinygrad.runtime',\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "test/external/external_benchmark_openpilot.py",
                ),
            ),
            modified: Some(
                Filename(
                    "test/external/external_benchmark_openpilot.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    new_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "import time, sys, hashlib\n",
                        ),
                        Context(
                            "from pathlib import Path\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "from tinygrad import Tensor, dtypes, TinyJit\n",
                        ),
                        Context(
                            "from tinygrad.helpers import IMAGE, GlobalCounters, fetch, colored, getenv, trange\n",
                        ),
                        Context(
                            "import numpy as np\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "test/external/external_model_benchmark.py",
                ),
            ),
            modified: Some(
                Filename(
                    "test/external/external_model_benchmark.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 4,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 4,
                        len: 7,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "torch.set_num_threads(1)\n",
                        ),
                        Context(
                            "import onnxruntime as ort\n",
                        ),
                        Context(
                            "from onnx2torch import convert\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "from tinygrad.helpers import OSX, DEBUG, fetch, getenv\n",
                        ),
                        Context(
                            "from tinygrad.dtype import _to_np_dtype\n",
                        ),
                        Context(
                            "from tinygrad import Tensor, Device, dtypes\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "test/external/external_test_onnx_backend.py",
                ),
            ),
            modified: Some(
                Filename(
                    "test/external/external_test_onnx_backend.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 6,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 6,
                        len: 7,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "from tinygrad import Tensor, Device, dtypes\n",
                        ),
                        Context(
                            "from tinygrad.helpers import getenv, OSX\n",
                        ),
                        Context(
                            "from tinygrad.device import is_dtype_supported\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "\n",
                        ),
                        Context(
                            "# pip3 install tabulate\n",
                        ),
                        Context(
                            "pytest_plugins = 'onnx.backend.test.report',\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "test/external/external_test_onnx_ops.py",
                ),
            ),
            modified: Some(
                Filename(
                    "test/external/external_test_onnx_ops.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 5,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 5,
                        len: 7,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "from typing import Any\n",
                        ),
                        Context(
                            "import unittest, onnx, tempfile\n",
                        ),
                        Context(
                            "from tinygrad import dtypes, Tensor\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "import numpy as np\n",
                        ),
                        Context(
                            "from extra.onnx_helpers import validate\n",
                        ),
                        Context(
                            "from onnx.defs import ONNX_DOMAIN, AI_ONNX_PREVIEW_TRAINING_DOMAIN\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "test/external/external_test_onnx_runner.py",
                ),
            ),
            modified: Some(
                Filename(
                    "test/external/external_test_onnx_runner.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 3,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 3,
                        len: 7,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "from tinygrad import dtypes, Tensor\n",
                        ),
                        Context(
                            "from tinygrad.uop.ops import Ops\n",
                        ),
                        Context(
                            "from tinygrad.device import is_dtype_supported\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner, OnnxDataType\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner, OnnxDataType\n",
                        ),
                        Context(
                            "from hypothesis import given, strategies as st\n",
                        ),
                        Context(
                            "\n",
                        ),
                        Context(
                            "# copied from test_const_folding.py\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "test/models/test_onnx.py",
                ),
            ),
            modified: Some(
                Filename(
                    "test/models/test_onnx.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    new_range: HunkRange {
                        start: 1,
                        len: 6,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "#!/usr/bin/env python\n",
                        ),
                        Context(
                            "import unittest\n",
                        ),
                        Context(
                            "import numpy as np\n",
                        ),
                        Delete(
                            "from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "from tinygrad.device import Device\n",
                        ),
                        Context(
                            "from tinygrad.helpers import fetch, Context\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "test/test_ops.py",
                ),
            ),
            modified: Some(
                Filename(
                    "test/test_ops.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 8,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 8,
                        len: 7,
                    },
                    function_context: None,
                    lines: [
                        Context(
                            "from tinygrad.device import is_dtype_supported\n",
                        ),
                        Context(
                            "\n",
                        ),
                        Context(
                            "if getenv(\"TINY_BACKEND\"):\n",
                        ),
                        Delete(
                            "  import tinygrad.frontend.torch # noqa: F401 # pylint: disable=unused-import\n",
                        ),
                        Insert(
                            "  import tinygrad.nn.torch # noqa: F401 # pylint: disable=unused-import\n",
                        ),
                        Context(
                            "  torch.set_default_device(\"tiny\")\n",
                        ),
                        Context(
                            "\n",
                        ),
                        Context(
                            "if CI:\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "test/test_quantize_onnx.py",
                ),
            ),
            modified: Some(
                Filename(
                    "test/test_quantize_onnx.py",
                ),
            ),
            hunks: [
                Hunk {
                    old_range: HunkRange {
                        start: 68,
                        len: 7,
                    },
                    new_range: HunkRange {
                        start: 68,
                        len: 7,
                    },
                    function_context: Some(
                        "def test_quant_128(self, sz=128):\n",
                    ),
                    lines: [
                        Context(
                            "      import onnx # noqa: F401 # pylint: disable=unused-import\n",
                        ),
                        Context(
                            "    except ImportError:\n",
                        ),
                        Context(
                            "      raise unittest.SkipTest()\n",
                        ),
                        Delete(
                            "    from tinygrad.frontend.onnx import OnnxRunner\n",
                        ),
                        Insert(
                            "    from tinygrad.nn.onnx import OnnxRunner\n",
                        ),
                        Context(
                            "    out_file = get_quantized_model(sz)\n",
                        ),
                        Context(
                            "    run_onnx = OnnxRunner(out_file)\n",
                        ),
                        Context(
                            "    inp = Tensor(np.random.uniform(size=(sz, sz)).astype(np.float32))\n",
                        ),
                    ],
                },
            ],
        },
        Patch {
            original: Some(
                Filename(
                    "tinygrad/frontend/__init__.py",
                ),
            ),
            modified: Some(
                Filename(
                    "tinygrad/frontend/__init__.py",
                ),
            ),
            hunks: [],
        },
        Patch {
            original: Some(
                Filename(
                    "tinygrad/frontend/onnx.py",
                ),
            ),
            modified: Some(
                Filename(
                    "tinygrad/nn/onnx.py",
                ),
            ),
            hunks: [],
        },
        Patch {
            original: Some(
                Filename(
                    "tinygrad/frontend/torch.py",
                ),
            ),
            modified: Some(
                Filename(
                    "tinygrad/nn/torch.py",
                ),
            ),
            hunks: [],
        },
    ],
)
