cuda-morph 0.9.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. cuda_morph-0.9.1/LICENSE +189 -0
  2. cuda_morph-0.9.1/PKG-INFO +167 -0
  3. cuda_morph-0.9.1/README.md +126 -0
  4. cuda_morph-0.9.1/pyproject.toml +90 -0
  5. cuda_morph-0.9.1/setup.cfg +4 -0
  6. cuda_morph-0.9.1/src/ascend_compat/__init__.py +207 -0
  7. cuda_morph-0.9.1/src/ascend_compat/__main__.py +34 -0
  8. cuda_morph-0.9.1/src/ascend_compat/_backend.py +334 -0
  9. cuda_morph-0.9.1/src/ascend_compat/_exceptions.py +69 -0
  10. cuda_morph-0.9.1/src/ascend_compat/_logging.py +124 -0
  11. cuda_morph-0.9.1/src/ascend_compat/backends/__init__.py +49 -0
  12. cuda_morph-0.9.1/src/ascend_compat/backends/ascend.py +61 -0
  13. cuda_morph-0.9.1/src/ascend_compat/backends/cambricon.py +82 -0
  14. cuda_morph-0.9.1/src/ascend_compat/backends/intel.py +74 -0
  15. cuda_morph-0.9.1/src/ascend_compat/backends/registry.py +138 -0
  16. cuda_morph-0.9.1/src/ascend_compat/backends/rocm.py +106 -0
  17. cuda_morph-0.9.1/src/ascend_compat/bench.py +650 -0
  18. cuda_morph-0.9.1/src/ascend_compat/cli/__init__.py +66 -0
  19. cuda_morph-0.9.1/src/ascend_compat/cli/_info.py +49 -0
  20. cuda_morph-0.9.1/src/ascend_compat/cli/_porter.py +71 -0
  21. cuda_morph-0.9.1/src/ascend_compat/cli/_scanner.py +368 -0
  22. cuda_morph-0.9.1/src/ascend_compat/cli/bench.py +33 -0
  23. cuda_morph-0.9.1/src/ascend_compat/cli/check.py +35 -0
  24. cuda_morph-0.9.1/src/ascend_compat/cli/compile.py +27 -0
  25. cuda_morph-0.9.1/src/ascend_compat/cli/doctor.py +19 -0
  26. cuda_morph-0.9.1/src/ascend_compat/cli/error.py +13 -0
  27. cuda_morph-0.9.1/src/ascend_compat/cli/info.py +12 -0
  28. cuda_morph-0.9.1/src/ascend_compat/cli/port.py +18 -0
  29. cuda_morph-0.9.1/src/ascend_compat/cli/quant.py +14 -0
  30. cuda_morph-0.9.1/src/ascend_compat/cli/run.py +40 -0
  31. cuda_morph-0.9.1/src/ascend_compat/cli/scaffold.py +31 -0
  32. cuda_morph-0.9.1/src/ascend_compat/cli/security.py +29 -0
  33. cuda_morph-0.9.1/src/ascend_compat/cli/verify.py +23 -0
  34. cuda_morph-0.9.1/src/ascend_compat/cli/vllm.py +19 -0
  35. cuda_morph-0.9.1/src/ascend_compat/cli.py +879 -0
  36. cuda_morph-0.9.1/src/ascend_compat/cuda_shim/__init__.py +40 -0
  37. cuda_morph-0.9.1/src/ascend_compat/cuda_shim/_import_hook.py +123 -0
  38. cuda_morph-0.9.1/src/ascend_compat/cuda_shim/_monkey_patch.py +569 -0
  39. cuda_morph-0.9.1/src/ascend_compat/cuda_shim/_patch_manager.py +313 -0
  40. cuda_morph-0.9.1/src/ascend_compat/cuda_shim/_registry.py +195 -0
  41. cuda_morph-0.9.1/src/ascend_compat/cuda_shim/compile_helpers.py +603 -0
  42. cuda_morph-0.9.1/src/ascend_compat/cuda_shim/dtype_manager.py +307 -0
  43. cuda_morph-0.9.1/src/ascend_compat/cuda_shim/quantization.py +279 -0
  44. cuda_morph-0.9.1/src/ascend_compat/device.py +127 -0
  45. cuda_morph-0.9.1/src/ascend_compat/doctor/__init__.py +40 -0
  46. cuda_morph-0.9.1/src/ascend_compat/doctor/env_setup.py +507 -0
  47. cuda_morph-0.9.1/src/ascend_compat/doctor/error_codes.py +408 -0
  48. cuda_morph-0.9.1/src/ascend_compat/doctor/fallback_monitor.py +274 -0
  49. cuda_morph-0.9.1/src/ascend_compat/doctor/op_auditor.py +287 -0
  50. cuda_morph-0.9.1/src/ascend_compat/doctor/security_check.py +274 -0
  51. cuda_morph-0.9.1/src/ascend_compat/doctor/version_check.py +254 -0
  52. cuda_morph-0.9.1/src/ascend_compat/ecosystem/__init__.py +23 -0
  53. cuda_morph-0.9.1/src/ascend_compat/ecosystem/_flash_attn_hook.py +134 -0
  54. cuda_morph-0.9.1/src/ascend_compat/ecosystem/deepspeed_patch.py +180 -0
  55. cuda_morph-0.9.1/src/ascend_compat/ecosystem/flash_attn.py +334 -0
  56. cuda_morph-0.9.1/src/ascend_compat/ecosystem/transformers_patch.py +223 -0
  57. cuda_morph-0.9.1/src/ascend_compat/ecosystem/triton_bridge.py +188 -0
  58. cuda_morph-0.9.1/src/ascend_compat/ecosystem/vllm_patch.py +289 -0
  59. cuda_morph-0.9.1/src/ascend_compat/exceptions.py +41 -0
  60. cuda_morph-0.9.1/src/ascend_compat/kernel_helper/__init__.py +31 -0
  61. cuda_morph-0.9.1/src/ascend_compat/kernel_helper/scaffold.py +681 -0
  62. cuda_morph-0.9.1/src/ascend_compat/kernel_helper/spec.py +128 -0
  63. cuda_morph-0.9.1/src/ascend_compat/memory.py +83 -0
  64. cuda_morph-0.9.1/src/ascend_compat/ops.py +147 -0
  65. cuda_morph-0.9.1/src/ascend_compat/py.typed +0 -0
  66. cuda_morph-0.9.1/src/ascend_compat/streams.py +62 -0
  67. cuda_morph-0.9.1/src/ascend_compat/validation/__init__.py +21 -0
  68. cuda_morph-0.9.1/src/ascend_compat/validation/op_verifier.py +365 -0
  69. cuda_morph-0.9.1/src/cuda_morph.egg-info/PKG-INFO +167 -0
  70. cuda_morph-0.9.1/src/cuda_morph.egg-info/SOURCES.txt +98 -0
  71. cuda_morph-0.9.1/src/cuda_morph.egg-info/dependency_links.txt +1 -0
  72. cuda_morph-0.9.1/src/cuda_morph.egg-info/entry_points.txt +3 -0
  73. cuda_morph-0.9.1/src/cuda_morph.egg-info/requires.txt +16 -0
  74. cuda_morph-0.9.1/src/cuda_morph.egg-info/top_level.txt +1 -0
  75. cuda_morph-0.9.1/tests/test_backend.py +65 -0
  76. cuda_morph-0.9.1/tests/test_backends.py +259 -0
  77. cuda_morph-0.9.1/tests/test_bench.py +188 -0
  78. cuda_morph-0.9.1/tests/test_cli.py +442 -0
  79. cuda_morph-0.9.1/tests/test_compile_helpers.py +197 -0
  80. cuda_morph-0.9.1/tests/test_doctor.py +189 -0
  81. cuda_morph-0.9.1/tests/test_dtype_manager.py +136 -0
  82. cuda_morph-0.9.1/tests/test_ecosystem.py +215 -0
  83. cuda_morph-0.9.1/tests/test_end_to_end.py +288 -0
  84. cuda_morph-0.9.1/tests/test_env_setup.py +195 -0
  85. cuda_morph-0.9.1/tests/test_error_codes_expanded.py +102 -0
  86. cuda_morph-0.9.1/tests/test_flash_attn_hook.py +83 -0
  87. cuda_morph-0.9.1/tests/test_hardware.py +399 -0
  88. cuda_morph-0.9.1/tests/test_import_hook.py +53 -0
  89. cuda_morph-0.9.1/tests/test_integration.py +444 -0
  90. cuda_morph-0.9.1/tests/test_kernel_helper.py +236 -0
  91. cuda_morph-0.9.1/tests/test_launcher.py +71 -0
  92. cuda_morph-0.9.1/tests/test_monkey_patch.py +112 -0
  93. cuda_morph-0.9.1/tests/test_op_auditor.py +125 -0
  94. cuda_morph-0.9.1/tests/test_patch_manager.py +321 -0
  95. cuda_morph-0.9.1/tests/test_performance.py +155 -0
  96. cuda_morph-0.9.1/tests/test_quantization.py +151 -0
  97. cuda_morph-0.9.1/tests/test_registry.py +68 -0
  98. cuda_morph-0.9.1/tests/test_stress.py +207 -0
  99. cuda_morph-0.9.1/tests/test_triton_bridge.py +104 -0
  100. cuda_morph-0.9.1/tests/test_vllm_patch.py +113 -0
@@ -0,0 +1,189 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work.
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including
48
+ the original version of the Work and any modifications or additions
49
+ to that Work or Derivative Works thereof, that is intentionally
50
+ submitted to the Licensor for inclusion in the Work by the copyright owner
51
+ or by an individual or Legal Entity authorized to submit on behalf of
52
+ the copyright owner. For the purposes of this definition, "submitted"
53
+ means any form of electronic, verbal, or written communication sent
54
+ to the Licensor or its representatives, including but not limited to
55
+ communication on electronic mailing lists, source code control systems,
56
+ and issue tracking systems that are managed by, or on behalf of, the
57
+ Licensor for the purpose of discussing and improving the Work, but
58
+ excluding communication that is conspicuously marked or otherwise
59
+ designated in writing by the copyright owner as "Not a Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity
62
+ on behalf of whom a Contribution has been received by the Licensor and
63
+ subsequently incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of
66
+ this License, each Contributor hereby grants to You a perpetual,
67
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
68
+ copyright license to reproduce, prepare Derivative Works of,
69
+ publicly display, publicly perform, sublicense, and distribute the
70
+ Work and such Derivative Works in Source or Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of
73
+ this License, each Contributor hereby grants to You a perpetual,
74
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
75
+ (except as stated in this section) patent license to make, have made,
76
+ use, offer to sell, sell, import, and otherwise transfer the Work,
77
+ where such license applies only to those patent claims licensable
78
+ by such Contributor that are necessarily infringed by their
79
+ Contribution(s) alone or by combination of their Contribution(s)
80
+ with the Work to which such Contribution(s) was submitted. If You
81
+ institute patent litigation against any entity (including a
82
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
83
+ or a Contribution incorporated within the Work constitutes direct
84
+ or contributory patent infringement, then any patent licenses
85
+ granted to You under this License for that Work shall terminate
86
+ as of the date such litigation is filed.
87
+
88
+ 4. Redistribution. You may reproduce and distribute copies of the
89
+ Work or Derivative Works thereof in any medium, with or without
90
+ modifications, and in Source or Object form, provided that You
91
+ meet the following conditions:
92
+
93
+ (a) You must give any other recipients of the Work or
94
+ Derivative Works a copy of this License; and
95
+
96
+ (b) You must cause any modified files to carry prominent notices
97
+ stating that You changed the files; and
98
+
99
+ (c) You must retain, in the Source form of any Derivative Works
100
+ that You distribute, all copyright, patent, trademark, and
101
+ attribution notices from the Source form of the Work,
102
+ excluding those notices that do not pertain to any part of
103
+ the Derivative Works; and
104
+
105
+ (d) If the Work includes a "NOTICE" text file as part of its
106
+ distribution, then any Derivative Works that You distribute must
107
+ include a readable copy of the attribution notices contained
108
+ within such NOTICE file, excluding any notices that do not
109
+ pertain to any part of the Derivative Works, in at least one
110
+ of the following places: within a NOTICE text file distributed
111
+ as part of the Derivative Works; within the Source form or
112
+ documentation, if provided along with the Derivative Works; or,
113
+ within a display generated by the Derivative Works, if and
114
+ wherever such third-party notices normally appear. The contents
115
+ of the NOTICE file are for informational purposes only and
116
+ do not modify the License. You may add Your own attribution
117
+ notices within Derivative Works that You distribute, alongside
118
+ or as an addendum to the NOTICE text from the Work, provided
119
+ that such additional attribution notices cannot be construed
120
+ as modifying the License.
121
+
122
+ You may add Your own copyright statement to Your modifications and
123
+ may provide additional or different license terms and conditions
124
+ for use, reproduction, or distribution of Your modifications, or
125
+ for any such Derivative Works as a whole, provided Your use,
126
+ reproduction, and distribution of the Work otherwise complies with
127
+ the conditions stated in this License.
128
+
129
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
130
+ any Contribution intentionally submitted for inclusion in the Work
131
+ by You to the Licensor shall be under the terms and conditions of
132
+ this License, without any additional terms or conditions.
133
+ Notwithstanding the above, nothing herein shall supersede or modify
134
+ the terms of any separate license agreement you may have executed
135
+ with Licensor regarding such Contributions.
136
+
137
+ 6. Trademarks. This License does not grant permission to use the trade
138
+ names, trademarks, service marks, or product names of the Licensor,
139
+ except as required for reasonable and customary use in describing the
140
+ origin of the Work and reproducing the content of the NOTICE file.
141
+
142
+ 7. Disclaimer of Warranty. Unless required by applicable law or
143
+ agreed to in writing, Licensor provides the Work (and each
144
+ Contributor provides its Contributions) on an "AS IS" BASIS,
145
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
146
+ implied, including, without limitation, any warranties or conditions
147
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
148
+ PARTICULAR PURPOSE. You are solely responsible for determining the
149
+ appropriateness of using or redistributing the Work and assume any
150
+ risks associated with Your exercise of permissions under this License.
151
+
152
+ 8. Limitation of Liability. In no event and under no legal theory,
153
+ whether in tort (including negligence), contract, or otherwise,
154
+ unless required by applicable law (such as deliberate and grossly
155
+ negligent acts) or agreed to in writing, shall any Contributor be
156
+ liable to You for damages, including any direct, indirect, special,
157
+ incidental, or consequential damages of any character arising as a
158
+ result of this License or out of the use or inability to use the
159
+ Work (including but not limited to damages for loss of goodwill,
160
+ work stoppage, computer failure or malfunction, or any and all
161
+ other commercial damages or losses), even if such Contributor
162
+ has been advised of the possibility of such damages.
163
+
164
+ 9. Accepting Warranty or Additional Liability. While redistributing
165
+ the Work or Derivative Works thereof, You may choose to offer,
166
+ and charge a fee for, acceptance of support, warranty, indemnity,
167
+ or other liability obligations and/or rights consistent with this
168
+ License. However, in accepting such obligations, You may act only
169
+ on Your own behalf and on Your sole responsibility, not on behalf
170
+ of any other Contributor, and only if You agree to indemnify,
171
+ defend, and hold each Contributor harmless for any liability
172
+ incurred by, or claims asserted against, such Contributor by reason
173
+ of your accepting any such warranty or additional liability.
174
+
175
+ END OF TERMS AND CONDITIONS
176
+
177
+ Copyright 2026 ascend-compat contributors
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License");
180
+ you may not use this file except in compliance with the License.
181
+ You may obtain a copy of the License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software
186
+ distributed under the License is distributed on an "AS IS" BASIS,
187
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
+ See the License for the specific language governing permissions and
189
+ limitations under the License.
@@ -0,0 +1,167 @@
1
+ Metadata-Version: 2.4
2
+ Name: cuda-morph
3
+ Version: 0.9.1
4
+ Summary: CUDA-to-Ascend ecosystem compatibility bridge — fixes the last mile between torch_npu and your existing CUDA code
5
+ Author: cuda-morph contributors
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/JosephAhn23/cuda-morph
8
+ Project-URL: Repository, https://github.com/JosephAhn23/cuda-morph
9
+ Project-URL: Documentation, https://github.com/JosephAhn23/cuda-morph#readme
10
+ Project-URL: Issues, https://github.com/JosephAhn23/cuda-morph/issues
11
+ Keywords: pytorch,cuda,ascend,npu,cann,huawei,compatibility,shim
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: torch>=2.0.0
28
+ Requires-Dist: click>=8.0
29
+ Requires-Dist: libcst>=1.0
30
+ Provides-Extra: ascend
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=7.0; extra == "dev"
33
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
34
+ Requires-Dist: pytest-mock>=3.10; extra == "dev"
35
+ Requires-Dist: mypy>=1.0; extra == "dev"
36
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
37
+ Provides-Extra: docs
38
+ Requires-Dist: mkdocs>=1.5; extra == "docs"
39
+ Requires-Dist: mkdocs-material>=9.0; extra == "docs"
40
+ Dynamic: license-file
41
+
42
+ # cuda-morph
43
+
44
+ Run PyTorch workloads on non-NVIDIA hardware with minimal code changes.
45
+
46
+ <p>
47
+ <img src="https://img.shields.io/badge/python-3.8%2B-1f6feb?style=for-the-badge&logo=python&logoColor=white" alt="Python 3.8+" />
48
+ <img src="https://img.shields.io/badge/status-alpha-6e40c9?style=for-the-badge" alt="Alpha status" />
49
+ <img src="https://img.shields.io/badge/license-Apache%202.0-0d1117?style=for-the-badge" alt="Apache 2.0 license" />
50
+ </p>
51
+
52
+ ![cuda-morph dark hero](assets/readme-hero-dark.svg)
53
+
54
+ Existing CUDA-style PyTorch scripts keep running — `cuda-morph` redirects calls to available backends or falls back to CPU.
55
+
56
+ ---
57
+
58
+ ## Why this exists
59
+
60
+ A lot of ML code assumes `torch.cuda` everywhere. On non-NVIDIA setups, that often means immediate runtime errors and expensive rewrites.
61
+
62
+ `cuda-morph` is a runtime compatibility layer that helps you keep the same workflow and ship faster.
63
+
64
+ ---
65
+
66
+ ## Visual walkthrough
67
+
68
+ ![cuda-morph workflow dark](assets/readme-workflow-dark.svg)
69
+
70
+ 1. Start with existing CUDA-oriented code.
71
+ 2. Activate `cuda-morph`.
72
+ 3. Run with backend-aware routing and fallback behavior.
73
+
74
+ ---
75
+
76
+ ## Quick start
77
+
78
+ ```bash
79
+ pip install cuda-morph
80
+ ```
81
+
82
+ ```python
83
+ import ascend_compat
84
+ ascend_compat.activate()
85
+
86
+ # Existing CUDA-style code stays the same
87
+ model = model.cuda()
88
+ ```
89
+
90
+ ```bash
91
+ cuda-morph info
92
+ cuda-morph check model.py
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Core capabilities
98
+
99
+ - Zero-rewrite activation for many CUDA-style PyTorch flows.
100
+ - Backend routing across Ascend / ROCm / Intel XPU / CPU fallback paths.
101
+ - CLI tooling for environment checks, porting hints, and validation commands.
102
+ - Ecosystem patches for key libraries (current depth varies by backend).
103
+
104
+ Full matrix: [docs/compatibility_matrix.md](docs/compatibility_matrix.md)
105
+
106
+ ---
107
+
108
+ ## Validation snapshot
109
+
110
+ ![cuda-morph cli dark](assets/readme-cli-dark.svg)
111
+ ![ROCm .cuda() proof screenshot](assets/amd-rocm-cuda-proof.png)
112
+
113
+ - 460+ tests passing in CPU-fallback mode.
114
+ - Real hardware proof captured on RunPod AMD ROCm: `.cuda()` matmul ran on `cuda:0` and reported `AMD Radeon Graphics`.
115
+ - Core `.cuda()` routing on non-NVIDIA hardware is now validated; broader operator and ecosystem coverage is still in progress.
116
+
117
+ If you can test on non-NVIDIA accelerators, feedback is highly valuable: [open an issue](https://github.com/JosephAhn23/cuda-morph/issues).
118
+
119
+ ---
120
+
121
+ ## Backend status (current)
122
+
123
+ | Backend | Hardware | Status |
124
+ |---------|----------|--------|
125
+ | **Huawei Ascend** | 910B, 310P | Full shim + ecosystem patches (flash-attn, HuggingFace, DeepSpeed, vLLM). Needs hardware validation. |
126
+ | **AMD ROCm** | MI210, MI250X, MI300X | Detection + device routing. Ecosystem patches not yet implemented. |
127
+ | **Intel XPU** | Max 1550, Flex, Arc | Detection + device routing. Ecosystem patches not yet implemented. |
128
+ | **Cambricon** | MLU370, MLU590 | Detection + device routing. Ecosystem patches not yet implemented. |
129
+
130
+ ---
131
+
132
+ ## CLI
133
+
134
+ ```bash
135
+ cuda-morph check model.py # check a script for compatibility issues
136
+ cuda-morph port model.py # generate porting suggestions
137
+ cuda-morph doctor # environment diagnostics
138
+ cuda-morph doctor --full
139
+ cuda-morph verify --device npu
140
+ cuda-morph bench overhead
141
+ cuda-morph info
142
+ ```
143
+
144
+ ---
145
+
146
+ ## Development
147
+
148
+ ```bash
149
+ git clone https://github.com/JosephAhn23/cuda-morph.git
150
+ cd cuda-morph
151
+ pip install -e ".[dev]"
152
+ pytest tests/ -v
153
+ pytest tests/ -v --run-hardware
154
+ ```
155
+
156
+ ---
157
+
158
+ ## See also
159
+
160
+ - [STRATEGY.md](STRATEGY.md)
161
+ - [VALIDATION_STATUS.md](VALIDATION_STATUS.md)
162
+ - [MIGRATION.md](MIGRATION.md)
163
+ - [docs/README_zh.md](docs/README_zh.md)
164
+
165
+ ## License
166
+
167
+ Apache 2.0
@@ -0,0 +1,126 @@
1
+ # cuda-morph
2
+
3
+ Run PyTorch workloads on non-NVIDIA hardware with minimal code changes.
4
+
5
+ <p>
6
+ <img src="https://img.shields.io/badge/python-3.8%2B-1f6feb?style=for-the-badge&logo=python&logoColor=white" alt="Python 3.8+" />
7
+ <img src="https://img.shields.io/badge/status-alpha-6e40c9?style=for-the-badge" alt="Alpha status" />
8
+ <img src="https://img.shields.io/badge/license-Apache%202.0-0d1117?style=for-the-badge" alt="Apache 2.0 license" />
9
+ </p>
10
+
11
+ ![cuda-morph dark hero](assets/readme-hero-dark.svg)
12
+
13
+ Existing CUDA-style PyTorch scripts keep running — `cuda-morph` redirects calls to available backends or falls back to CPU.
14
+
15
+ ---
16
+
17
+ ## Why this exists
18
+
19
+ A lot of ML code assumes `torch.cuda` everywhere. On non-NVIDIA setups, that often means immediate runtime errors and expensive rewrites.
20
+
21
+ `cuda-morph` is a runtime compatibility layer that helps you keep the same workflow and ship faster.
22
+
23
+ ---
24
+
25
+ ## Visual walkthrough
26
+
27
+ ![cuda-morph workflow dark](assets/readme-workflow-dark.svg)
28
+
29
+ 1. Start with existing CUDA-oriented code.
30
+ 2. Activate `cuda-morph`.
31
+ 3. Run with backend-aware routing and fallback behavior.
32
+
33
+ ---
34
+
35
+ ## Quick start
36
+
37
+ ```bash
38
+ pip install cuda-morph
39
+ ```
40
+
41
+ ```python
42
+ import ascend_compat
43
+ ascend_compat.activate()
44
+
45
+ # Existing CUDA-style code stays the same
46
+ model = model.cuda()
47
+ ```
48
+
49
+ ```bash
50
+ cuda-morph info
51
+ cuda-morph check model.py
52
+ ```
53
+
54
+ ---
55
+
56
+ ## Core capabilities
57
+
58
+ - Zero-rewrite activation for many CUDA-style PyTorch flows.
59
+ - Backend routing across Ascend / ROCm / Intel XPU / CPU fallback paths.
60
+ - CLI tooling for environment checks, porting hints, and validation commands.
61
+ - Ecosystem patches for key libraries (current depth varies by backend).
62
+
63
+ Full matrix: [docs/compatibility_matrix.md](docs/compatibility_matrix.md)
64
+
65
+ ---
66
+
67
+ ## Validation snapshot
68
+
69
+ ![cuda-morph cli dark](assets/readme-cli-dark.svg)
70
+ ![ROCm .cuda() proof screenshot](assets/amd-rocm-cuda-proof.png)
71
+
72
+ - 460+ tests passing in CPU-fallback mode.
73
+ - Real hardware proof captured on RunPod AMD ROCm: `.cuda()` matmul ran on `cuda:0` and reported `AMD Radeon Graphics`.
74
+ - Core `.cuda()` routing on non-NVIDIA hardware is now validated; broader operator and ecosystem coverage is still in progress.
75
+
76
+ If you can test on non-NVIDIA accelerators, feedback is highly valuable: [open an issue](https://github.com/JosephAhn23/cuda-morph/issues).
77
+
78
+ ---
79
+
80
+ ## Backend status (current)
81
+
82
+ | Backend | Hardware | Status |
83
+ |---------|----------|--------|
84
+ | **Huawei Ascend** | 910B, 310P | Full shim + ecosystem patches (flash-attn, HuggingFace, DeepSpeed, vLLM). Needs hardware validation. |
85
+ | **AMD ROCm** | MI210, MI250X, MI300X | Detection + device routing. Ecosystem patches not yet implemented. |
86
+ | **Intel XPU** | Max 1550, Flex, Arc | Detection + device routing. Ecosystem patches not yet implemented. |
87
+ | **Cambricon** | MLU370, MLU590 | Detection + device routing. Ecosystem patches not yet implemented. |
88
+
89
+ ---
90
+
91
+ ## CLI
92
+
93
+ ```bash
94
+ cuda-morph check model.py # check a script for compatibility issues
95
+ cuda-morph port model.py # generate porting suggestions
96
+ cuda-morph doctor # environment diagnostics
97
+ cuda-morph doctor --full
98
+ cuda-morph verify --device npu
99
+ cuda-morph bench overhead
100
+ cuda-morph info
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Development
106
+
107
+ ```bash
108
+ git clone https://github.com/JosephAhn23/cuda-morph.git
109
+ cd cuda-morph
110
+ pip install -e ".[dev]"
111
+ pytest tests/ -v
112
+ pytest tests/ -v --run-hardware
113
+ ```
114
+
115
+ ---
116
+
117
+ ## See also
118
+
119
+ - [STRATEGY.md](STRATEGY.md)
120
+ - [VALIDATION_STATUS.md](VALIDATION_STATUS.md)
121
+ - [MIGRATION.md](MIGRATION.md)
122
+ - [docs/README_zh.md](docs/README_zh.md)
123
+
124
+ ## License
125
+
126
+ Apache 2.0
@@ -0,0 +1,90 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "cuda-morph"
7
+ version = "0.9.1"
8
+ description = "CUDA-to-Ascend ecosystem compatibility bridge — fixes the last mile between torch_npu and your existing CUDA code"
9
+ readme = "README.md"
10
+ license = {text = "Apache-2.0"}
11
+ requires-python = ">=3.8"
12
+ authors = [
13
+ {name = "cuda-morph contributors"},
14
+ ]
15
+ keywords = ["pytorch", "cuda", "ascend", "npu", "cann", "huawei", "compatibility", "shim"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "Intended Audience :: Science/Research",
20
+ "License :: OSI Approved :: Apache Software License",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.8",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
28
+ "Topic :: Software Development :: Libraries :: Python Modules",
29
+ ]
30
+ dependencies = [
31
+ "torch>=2.0.0",
32
+ "click>=8.0",
33
+ "libcst>=1.0",
34
+ ]
35
+
36
+ [project.optional-dependencies]
37
+ # torch_npu is installed separately from Huawei's repository — it is NOT on PyPI.
38
+ # Install via: pip install torch-npu (from Huawei's index or built from source)
39
+ # See: https://gitee.com/ascend/pytorch
40
+ ascend = []
41
+ dev = [
42
+ "pytest>=7.0",
43
+ "pytest-cov>=4.0",
44
+ "pytest-mock>=3.10",
45
+ "mypy>=1.0",
46
+ "ruff>=0.1.0",
47
+ ]
48
+ docs = [
49
+ "mkdocs>=1.5",
50
+ "mkdocs-material>=9.0",
51
+ ]
52
+
53
+ [project.scripts]
54
+ cuda-morph = "ascend_compat.cli:main"
55
+ ascend-compat = "ascend_compat.cli:main"
56
+
57
+ [project.urls]
58
+ Homepage = "https://github.com/JosephAhn23/cuda-morph"
59
+ Repository = "https://github.com/JosephAhn23/cuda-morph"
60
+ Documentation = "https://github.com/JosephAhn23/cuda-morph#readme"
61
+ Issues = "https://github.com/JosephAhn23/cuda-morph/issues"
62
+
63
+ [tool.setuptools.packages.find]
64
+ where = ["src"]
65
+
66
+ [tool.pytest.ini_options]
67
+ testpaths = ["tests"]
68
+ addopts = "-v --tb=short"
69
+ markers = [
70
+ "benchmark: performance regression tests (may be slow)",
71
+ "stress: stability/load tests (long-running, may use significant memory)",
72
+ "hardware: requires real Ascend NPU hardware (skipped without --run-hardware)",
73
+ ]
74
+
75
+ [tool.mypy]
76
+ python_version = "3.8"
77
+ warn_return_any = true
78
+ warn_unused_configs = true
79
+ disallow_untyped_defs = true
80
+
81
+ [tool.ruff]
82
+ target-version = "py38"
83
+ line-length = 100
84
+
85
+ [tool.ruff.lint]
86
+ select = ["E", "F", "W", "I", "N", "D", "UP"]
87
+ ignore = ["D100", "D104"] # Allow missing module/package docstrings at top level
88
+
89
+ [tool.ruff.lint.pydocstyle]
90
+ convention = "google"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+