Download compatibility/src/fidel_compatibility/kernel_build.py from 4E-AI/Fidel2.0-1B: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/4E-AI/Fidel2.0-1B/resolve/main/compatibility/src/fidel_compatibility/kernel_build.py
- Command line
-
hf download hf://4E-AI/Fidel2.0-1B/compatibility/src/fidel_compatibility/kernel_build.py
-
curl -L -o kernel_build.py https://huggingface.co/4E-AI/Fidel2.0-1B/resolve/main/compatibility/src/fidel_compatibility/kernel_build.py
1.15 kB
| """Stable, byte-verified CUDA input paths across source and wheel installations.""" | |
| import hashlib,os,tempfile | |
| from pathlib import Path | |
| def stable_source(path,cache_root=None): | |
| path=Path(path) | |
| if path.suffix!='.cu':raise ValueError('CUDA source required') | |
| raw=path.read_bytes();digest=hashlib.sha256(raw).hexdigest() | |
| root=Path(cache_root) if cache_root is not None else Path(os.environ.get('TORCH_EXTENSIONS_DIR',str(Path.home()/'.cache/torch_extensions')))/'fidel_sources' | |
| folder=root/digest;folder.mkdir(parents=True,exist_ok=True);target=folder/path.name | |
| if not target.exists(): | |
| with tempfile.NamedTemporaryFile(dir=folder,delete=False) as stream: | |
| temporary=Path(stream.name);stream.write(raw);stream.flush();os.fsync(stream.fileno()) | |
| try: | |
| try:os.link(temporary,target) | |
| except FileExistsError:pass | |
| finally:temporary.unlink() | |
| if hashlib.sha256(target.read_bytes()).hexdigest()!=digest: | |
| raise RuntimeError('Cached CUDA source bytes differ; refusing compilation') | |
| os.utime(target,(946684800,946684800)) | |
| return target | |