Add src/ehekim/__init__.py
Browse files- src/ehekim/__init__.py +45 -0
src/ehekim/__init__.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""e-hekim — Turkish medical semantic search and RAG over hospital articles.
|
| 2 |
+
|
| 3 |
+
Importing this package applies one environment compatibility fix before torch is
|
| 4 |
+
loaded; see :func:`_disable_torch_native_jit_if_unbuildable`.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sysconfig
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
__version__ = "1.0.0"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _disable_torch_native_jit_if_unbuildable() -> bool:
|
| 17 |
+
"""Fall back to aten kernels when Triton cannot JIT-compile on this machine.
|
| 18 |
+
|
| 19 |
+
torch >= 2.13 routes a few aten ops (e.g. ``bmm`` for the outer products in
|
| 20 |
+
Gemma-3 RoPE, which this project's embedding model uses) through Triton
|
| 21 |
+
kernels. Triton compiles a small CUDA shim at first use with the system
|
| 22 |
+
compiler, which requires the CPython development headers. On a machine with
|
| 23 |
+
only the Python *runtime* installed (no ``python3-devel`` / ``python3-dev``)
|
| 24 |
+
that compile fails with ``Python.h: No such file or directory`` and the
|
| 25 |
+
first embedding call dies — even though the model itself loaded fine.
|
| 26 |
+
|
| 27 |
+
``TORCH_DISABLE_NATIVE_JIT=1`` makes torch use its ordinary aten kernels
|
| 28 |
+
instead. The results are numerically equivalent; only the fused fast path is
|
| 29 |
+
given up. Setting it here, rather than asking every user to export a
|
| 30 |
+
variable, keeps ``uv run`` working out of the box on a stock system. It must
|
| 31 |
+
be set before torch is imported, hence its placement in the package
|
| 32 |
+
``__init__``.
|
| 33 |
+
|
| 34 |
+
An explicit value already present in the environment always wins.
|
| 35 |
+
"""
|
| 36 |
+
if os.environ.get("TORCH_DISABLE_NATIVE_JIT"):
|
| 37 |
+
return False
|
| 38 |
+
include_dir = sysconfig.get_config_var("INCLUDEPY")
|
| 39 |
+
if include_dir and Path(include_dir, "Python.h").exists():
|
| 40 |
+
return False # headers present, let Triton do its thing
|
| 41 |
+
os.environ["TORCH_DISABLE_NATIVE_JIT"] = "1"
|
| 42 |
+
return True
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
TORCH_NATIVE_JIT_DISABLED = _disable_torch_native_jit_if_unbuildable()
|