[Python] Add Torch dialect registration modules (#25251)

I hit this while profiling PyTorch graph import through Turbine/IREE.
MLIR's Python bindings look for `iree.compiler.dialects.torch` and
`torch_c`, but neither module exists. Failed dialect imports are retried
during type construction and operation inspection, producing roughly
38,000 failed lookups for D-FINE.

This adds standard Python namespace registrations for the existing
native Torch and TorchConversion dialects and includes them in the
Python package. Operations continue to use generic OpViews.

I've added coverage to the existing registration test, which fails
before and passes after the change. With LLVM/MLIR 23.1.2 in Wasm64,
D-FINE's graph import/preparation dropped from 15.3 s to 1.9 s, and its
first model call from 45.8 s to 32.0 s. CPU and WebGPU correctness
checks still pass.

Signed-off-by: anutosh491 <andersonbhat491@gmail.com>
diff --git a/compiler/bindings/python/CMakeLists.txt b/compiler/bindings/python/CMakeLists.txt
index 5129153..5132101 100644
--- a/compiler/bindings/python/CMakeLists.txt
+++ b/compiler/bindings/python/CMakeLists.txt
@@ -54,6 +54,16 @@
   ADD_TO_PARENT IREEPythonSources
 )
 
+# The Torch input plugin registers the native dialects. These Python modules
+# provide their namespace registrations without requiring Torch-MLIR OpViews.
+declare_mlir_python_sources(IREEPythonSources.Dialects.Torch
+  ADD_TO_PARENT IREEPythonSources.Dialects
+  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/iree/compiler"
+  SOURCES
+    dialects/torch.py
+    dialects/torch_c.py
+)
+
 declare_mlir_dialect_python_bindings(
   ADD_TO_PARENT IREEPythonSources.Dialects
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/iree/compiler"
diff --git a/compiler/bindings/python/iree/compiler/dialects/torch.py b/compiler/bindings/python/iree/compiler/dialects/torch.py
new file mode 100644
index 0000000..3baeb4f
--- /dev/null
+++ b/compiler/bindings/python/iree/compiler/dialects/torch.py
@@ -0,0 +1,14 @@
+# Copyright 2026 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+"""Python dialect registration; operations currently use generic OpViews."""
+
+from ._ods_common import _cext
+
+
+@_cext.register_dialect
+class _Dialect(_cext.ir.Dialect):
+    DIALECT_NAMESPACE = "torch"
diff --git a/compiler/bindings/python/iree/compiler/dialects/torch_c.py b/compiler/bindings/python/iree/compiler/dialects/torch_c.py
new file mode 100644
index 0000000..c096135
--- /dev/null
+++ b/compiler/bindings/python/iree/compiler/dialects/torch_c.py
@@ -0,0 +1,14 @@
+# Copyright 2026 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+"""Python dialect registration; operations currently use generic OpViews."""
+
+from ._ods_common import _cext
+
+
+@_cext.register_dialect
+class _Dialect(_cext.ir.Dialect):
+    DIALECT_NAMESPACE = "torch_c"
diff --git a/compiler/bindings/python/test/ir/registration_test.py b/compiler/bindings/python/test/ir/registration_test.py
index 33c8f00..e6dbc97 100644
--- a/compiler/bindings/python/test/ir/registration_test.py
+++ b/compiler/bindings/python/test/ir/registration_test.py
@@ -20,3 +20,17 @@
   """
     )
     print(input_module)
+
+
+# Torch input support is optional. When enabled, its Python dialect modules
+# should load normally for both namespace access and generic IR construction.
+with ir.Context() as ctx:
+    if ctx.is_registered_operation("torch.constant.int"):
+        from iree.compiler.dialects import torch, torch_c
+
+        assert isinstance(ctx.dialects["torch"], torch._Dialect)
+        assert isinstance(ctx.dialects["torch_c"], torch_c._Dialect)
+        tensor_type = ir.Type.parse("!torch.vtensor<[1],f32>")
+        for _ in range(3):
+            assert ir.Type.parse("!torch.vtensor<[1],f32>") == tensor_type
+        print("Torch Python dialect registration passed")