Spaces:
Sleeping
Sleeping
github-actions[bot]
commited on
Commit
·
20cfecf
1
Parent(s):
a62d768
Deploy from GitHub - 2026-01-19 04:19:46
Browse files- .gitattributes +0 -35
- .gitignore +0 -39
- compile_kernels.py +2 -1
- kernels/__init__.py +62 -5
- kernels/prebuilt/README.md +0 -64
- upload_kernels_to_dataset.py +159 -0
.gitattributes
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
__pycache__/
|
| 2 |
-
*.pyc
|
| 3 |
-
*.pyo
|
| 4 |
-
*.pyd
|
| 5 |
-
.Python
|
| 6 |
-
*.so
|
| 7 |
-
*.egg
|
| 8 |
-
*.egg-info/
|
| 9 |
-
dist/
|
| 10 |
-
build/
|
| 11 |
-
|
| 12 |
-
# Model weights (downloaded at runtime via GitHub releases)
|
| 13 |
-
models/*.pth
|
| 14 |
-
models/*.pt
|
| 15 |
-
|
| 16 |
-
# Test outputs
|
| 17 |
-
test_outputs/
|
| 18 |
-
*.jpg
|
| 19 |
-
*.png
|
| 20 |
-
!examples/*.jpg
|
| 21 |
-
!examples/*.png
|
| 22 |
-
|
| 23 |
-
# IDE
|
| 24 |
-
.vscode/
|
| 25 |
-
.idea/
|
| 26 |
-
*.swp
|
| 27 |
-
*.swo
|
| 28 |
-
|
| 29 |
-
# OS
|
| 30 |
-
.DS_Store
|
| 31 |
-
Thumbs.db
|
| 32 |
-
|
| 33 |
-
# Gradio
|
| 34 |
-
gradio_cached_examples/
|
| 35 |
-
flagged/
|
| 36 |
-
|
| 37 |
-
# BUT allow pre-compiled kernels in prebuilt/
|
| 38 |
-
!kernels/prebuilt/*.so
|
| 39 |
-
!kernels/prebuilt/*.pyd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
compile_kernels.py
CHANGED
|
@@ -73,11 +73,12 @@ try:
|
|
| 73 |
print("Compiling... (this may take 1-2 minutes)")
|
| 74 |
|
| 75 |
# Compile the kernel
|
|
|
|
| 76 |
module = load_inline(
|
| 77 |
name='fused_instance_norm',
|
|
|
|
| 78 |
cuda_sources=[cuda_source],
|
| 79 |
extra_cuda_cflags=extra_cuda_cflags,
|
| 80 |
-
with_pybind11=True,
|
| 81 |
verbose=False
|
| 82 |
)
|
| 83 |
|
|
|
|
| 73 |
print("Compiling... (this may take 1-2 minutes)")
|
| 74 |
|
| 75 |
# Compile the kernel
|
| 76 |
+
# Note: PyTorch 2.x requires cpp_sources even if empty (bindings are in CUDA)
|
| 77 |
module = load_inline(
|
| 78 |
name='fused_instance_norm',
|
| 79 |
+
cpp_sources=[], # Empty since bindings are in the .cu file
|
| 80 |
cuda_sources=[cuda_source],
|
| 81 |
extra_cuda_cflags=extra_cuda_cflags,
|
|
|
|
| 82 |
verbose=False
|
| 83 |
)
|
| 84 |
|
kernels/__init__.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
StyleForge CUDA Kernels Package
|
| 3 |
Custom CUDA kernels for accelerated neural style transfer.
|
| 4 |
|
| 5 |
-
For ZeroGPU: Pre-compiled kernels are
|
| 6 |
For local: Kernels are JIT-compiled if prebuilt not available.
|
| 7 |
"""
|
| 8 |
|
|
@@ -15,11 +15,59 @@ _CUDA_KERNELS_AVAILABLE = False
|
|
| 15 |
_FusedInstanceNorm2d = None
|
| 16 |
_KERNELS_COMPILED = False
|
| 17 |
|
| 18 |
-
# Check if running on ZeroGPU
|
| 19 |
-
_ZERO_GPU = os.environ.get('SPACE_ID', '')
|
| 20 |
|
| 21 |
# Path to pre-compiled kernels
|
| 22 |
_PREBUILT_PATH = Path(__file__).parent / "prebuilt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def check_cuda_kernels():
|
|
@@ -46,6 +94,7 @@ def get_fused_instance_norm(num_features, **kwargs):
|
|
| 46 |
def load_prebuilt_kernels():
|
| 47 |
"""
|
| 48 |
Try to load pre-compiled CUDA kernels from prebuilt/ directory.
|
|
|
|
| 49 |
|
| 50 |
Returns True if successful, False otherwise.
|
| 51 |
"""
|
|
@@ -54,10 +103,18 @@ def load_prebuilt_kernels():
|
|
| 54 |
if _KERNELS_COMPILED:
|
| 55 |
return _CUDA_KERNELS_AVAILABLE
|
| 56 |
|
| 57 |
-
# Check if prebuilt kernels exist
|
| 58 |
prebuilt_files = list(_PREBUILT_PATH.glob("*.so")) + list(_PREBUILT_PATH.glob("*.pyd"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
if not prebuilt_files:
|
| 60 |
-
print("No pre-compiled kernels found
|
| 61 |
return False
|
| 62 |
|
| 63 |
try:
|
|
|
|
| 2 |
StyleForge CUDA Kernels Package
|
| 3 |
Custom CUDA kernels for accelerated neural style transfer.
|
| 4 |
|
| 5 |
+
For ZeroGPU/HuggingFace: Pre-compiled kernels are downloaded from HF dataset.
|
| 6 |
For local: Kernels are JIT-compiled if prebuilt not available.
|
| 7 |
"""
|
| 8 |
|
|
|
|
| 15 |
_FusedInstanceNorm2d = None
|
| 16 |
_KERNELS_COMPILED = False
|
| 17 |
|
| 18 |
+
# Check if running on ZeroGPU/HuggingFace
|
| 19 |
+
_ZERO_GPU = os.environ.get('SPACE_ID', '') or os.environ.get('ZERO_GPU') == '1'
|
| 20 |
|
| 21 |
# Path to pre-compiled kernels
|
| 22 |
_PREBUILT_PATH = Path(__file__).parent / "prebuilt"
|
| 23 |
+
_PREBUILT_PATH.mkdir(exist_ok=True)
|
| 24 |
+
|
| 25 |
+
# HuggingFace dataset for prebuilt kernels
|
| 26 |
+
_KERNEL_DATASET = "oliau/styleforge-kernels" # You'll need to create this dataset
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _download_kernels_from_dataset():
|
| 30 |
+
"""Download pre-compiled kernels from HuggingFace dataset."""
|
| 31 |
+
try:
|
| 32 |
+
from huggingface_hub import hf_hub_download, HfFileSystem
|
| 33 |
+
fs = HfFileSystem()
|
| 34 |
+
|
| 35 |
+
# List all .so and .pyd files in the dataset
|
| 36 |
+
kernel_files = []
|
| 37 |
+
try:
|
| 38 |
+
files = fs.ls(f"datasets/{_KERNEL_DATASET}")
|
| 39 |
+
for f in files:
|
| 40 |
+
if f['name'].endswith(('.so', '.pyd')):
|
| 41 |
+
kernel_files.append(Path(f['name']).name)
|
| 42 |
+
except Exception:
|
| 43 |
+
# Dataset might not exist yet
|
| 44 |
+
return False
|
| 45 |
+
|
| 46 |
+
if not kernel_files:
|
| 47 |
+
return False
|
| 48 |
+
|
| 49 |
+
# Download each kernel file
|
| 50 |
+
for kernel_file in kernel_files:
|
| 51 |
+
try:
|
| 52 |
+
local_path = hf_hub_download(
|
| 53 |
+
repo_id=_KERNEL_DATASET,
|
| 54 |
+
filename=kernel_file,
|
| 55 |
+
repo_type="dataset",
|
| 56 |
+
local_dir=str(_PREBUILT_PATH.parent),
|
| 57 |
+
local_dir_use_symlinks=False
|
| 58 |
+
)
|
| 59 |
+
print(f"Downloaded kernel: {kernel_file}")
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print(f"Failed to download {kernel_file}: {e}")
|
| 62 |
+
continue
|
| 63 |
+
|
| 64 |
+
return True
|
| 65 |
+
except ImportError:
|
| 66 |
+
print("huggingface_hub not available, skipping kernel download")
|
| 67 |
+
return False
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f"Failed to download kernels from dataset: {e}")
|
| 70 |
+
return False
|
| 71 |
|
| 72 |
|
| 73 |
def check_cuda_kernels():
|
|
|
|
| 94 |
def load_prebuilt_kernels():
|
| 95 |
"""
|
| 96 |
Try to load pre-compiled CUDA kernels from prebuilt/ directory.
|
| 97 |
+
On HuggingFace, downloads from dataset if local files not found.
|
| 98 |
|
| 99 |
Returns True if successful, False otherwise.
|
| 100 |
"""
|
|
|
|
| 103 |
if _KERNELS_COMPILED:
|
| 104 |
return _CUDA_KERNELS_AVAILABLE
|
| 105 |
|
| 106 |
+
# Check if prebuilt kernels exist locally
|
| 107 |
prebuilt_files = list(_PREBUILT_PATH.glob("*.so")) + list(_PREBUILT_PATH.glob("*.pyd"))
|
| 108 |
+
|
| 109 |
+
# On HuggingFace Spaces, try downloading from dataset if not found locally
|
| 110 |
+
if not prebuilt_files and _ZERO_GPU:
|
| 111 |
+
print("No local pre-compiled kernels found. Trying HuggingFace dataset...")
|
| 112 |
+
if _download_kernels_from_dataset():
|
| 113 |
+
# Check again after download
|
| 114 |
+
prebuilt_files = list(_PREBUILT_PATH.glob("*.so")) + list(_PREBUILT_PATH.glob("*.pyd"))
|
| 115 |
+
|
| 116 |
if not prebuilt_files:
|
| 117 |
+
print("No pre-compiled kernels found")
|
| 118 |
return False
|
| 119 |
|
| 120 |
try:
|
kernels/prebuilt/README.md
DELETED
|
@@ -1,64 +0,0 @@
|
|
| 1 |
-
# Pre-Compiled CUDA Kernels
|
| 2 |
-
|
| 3 |
-
This directory contains pre-compiled CUDA kernels for use on Hugging Face Spaces.
|
| 4 |
-
|
| 5 |
-
## How to Compile Kernels Locally
|
| 6 |
-
|
| 7 |
-
To compile the CUDA kernels locally and upload them here:
|
| 8 |
-
|
| 9 |
-
### 1. Compile Locally
|
| 10 |
-
|
| 11 |
-
Run this script from the `huggingface-space` directory:
|
| 12 |
-
|
| 13 |
-
```bash
|
| 14 |
-
python compile_kernels.py
|
| 15 |
-
```
|
| 16 |
-
|
| 17 |
-
Or compile manually:
|
| 18 |
-
|
| 19 |
-
```bash
|
| 20 |
-
cd huggingface-space
|
| 21 |
-
python -c "
|
| 22 |
-
from kernels.cuda_build import compile_inline
|
| 23 |
-
from pathlib import Path
|
| 24 |
-
|
| 25 |
-
cuda_source = (Path('kernels') / 'instance_norm.cu').read_text()
|
| 26 |
-
module = compile_inline(
|
| 27 |
-
name='fused_instance_norm',
|
| 28 |
-
cuda_source=cuda_source,
|
| 29 |
-
functions=['forward'],
|
| 30 |
-
build_directory=Path('build'),
|
| 31 |
-
verbose=True
|
| 32 |
-
)
|
| 33 |
-
print('Compiled successfully!')
|
| 34 |
-
print(f'Module location: {module.__file__}')
|
| 35 |
-
"
|
| 36 |
-
```
|
| 37 |
-
|
| 38 |
-
### 2. Copy Compiled File
|
| 39 |
-
|
| 40 |
-
After compilation, copy the compiled `.so` file to this directory:
|
| 41 |
-
|
| 42 |
-
```bash
|
| 43 |
-
# Find the compiled file (usually in build/)
|
| 44 |
-
find build/ -name "*.so" -exec cp {} kernels/prebuilt/ \;
|
| 45 |
-
```
|
| 46 |
-
|
| 47 |
-
### 3. Commit and Push
|
| 48 |
-
|
| 49 |
-
```bash
|
| 50 |
-
git add kernels/prebuilt/
|
| 51 |
-
git commit -m "Add pre-compiled CUDA kernels"
|
| 52 |
-
git push
|
| 53 |
-
```
|
| 54 |
-
|
| 55 |
-
## Notes
|
| 56 |
-
|
| 57 |
-
- The compiled kernels are architecture-specific (e.g., `sm_70`, `sm_75`, `sm_86`)
|
| 58 |
-
- Hugging Face Spaces typically use Tesla T4 (sm_75) or A100 (sm_80)
|
| 59 |
-
- For maximum compatibility, compile with multiple compute capabilities
|
| 60 |
-
|
| 61 |
-
## Current Status
|
| 62 |
-
|
| 63 |
-
No pre-compiled kernels found. The app will use PyTorch's InstanceNorm2d fallback,
|
| 64 |
-
which is still GPU-accelerated but not as fast as custom fused kernels.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upload_kernels_to_dataset.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Upload pre-compiled CUDA kernels to Hugging Face Dataset.
|
| 4 |
+
|
| 5 |
+
This avoids git push issues with binary files on Hugging Face Spaces.
|
| 6 |
+
|
| 7 |
+
Usage:
|
| 8 |
+
python upload_kernels_to_dataset.py
|
| 9 |
+
|
| 10 |
+
The kernels will be uploaded to: huggingface.co/datasets/oliau/styleforge-kernels
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import sys
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
from huggingface_hub import HfApi, login
|
| 18 |
+
except ImportError:
|
| 19 |
+
print("ERROR: huggingface_hub not installed.")
|
| 20 |
+
print("Install with: pip install huggingface_hub")
|
| 21 |
+
sys.exit(1)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def upload_kernels():
|
| 25 |
+
"""Upload pre-compiled kernels to Hugging Face dataset."""
|
| 26 |
+
|
| 27 |
+
# Configuration
|
| 28 |
+
DATASET_ID = "oliau/styleforge-kernels"
|
| 29 |
+
PREBUILT_DIR = Path("kernels/prebuilt")
|
| 30 |
+
|
| 31 |
+
print("=" * 60)
|
| 32 |
+
print("StyleForge Kernel Uploader")
|
| 33 |
+
print("=" * 60)
|
| 34 |
+
print()
|
| 35 |
+
|
| 36 |
+
# Check if prebuilt directory exists
|
| 37 |
+
if not PREBUILT_DIR.exists():
|
| 38 |
+
print(f"ERROR: Prebuilt directory not found: {PREBUILT_DIR}")
|
| 39 |
+
print("Run compile_kernels.py first to generate the kernels.")
|
| 40 |
+
sys.exit(1)
|
| 41 |
+
|
| 42 |
+
# Find all kernel files
|
| 43 |
+
kernel_files = list(PREBUILT_DIR.glob("*.so")) + list(PREBUILT_DIR.glob("*.pyd"))
|
| 44 |
+
|
| 45 |
+
if not kernel_files:
|
| 46 |
+
print(f"ERROR: No kernel files found in {PREBUILT_DIR}")
|
| 47 |
+
print("Expected .so or .pyd files.")
|
| 48 |
+
sys.exit(1)
|
| 49 |
+
|
| 50 |
+
print(f"Found {len(kernel_files)} kernel file(s):")
|
| 51 |
+
for f in kernel_files:
|
| 52 |
+
size_kb = f.stat().st_size / 1024
|
| 53 |
+
print(f" - {f.name} ({size_kb:.1f} KB)")
|
| 54 |
+
print()
|
| 55 |
+
|
| 56 |
+
# Initialize HF API
|
| 57 |
+
api = HfApi()
|
| 58 |
+
|
| 59 |
+
# Check if user is logged in
|
| 60 |
+
try:
|
| 61 |
+
whoami = api.whoami()
|
| 62 |
+
print(f"Logged in as: {whoami.get('name', whoami.get('user', 'unknown'))}")
|
| 63 |
+
except Exception:
|
| 64 |
+
print("Not logged in to Hugging Face.")
|
| 65 |
+
print("Please run: huggingface-cli login")
|
| 66 |
+
print("Or set HF_TOKEN environment variable.")
|
| 67 |
+
sys.exit(1)
|
| 68 |
+
|
| 69 |
+
print()
|
| 70 |
+
print(f"Uploading to dataset: {DATASET_ID}")
|
| 71 |
+
print()
|
| 72 |
+
|
| 73 |
+
# Create dataset if it doesn't exist
|
| 74 |
+
try:
|
| 75 |
+
repo_info = api.repo_info(DATASET_ID, repo_type="dataset")
|
| 76 |
+
print(f"Dataset exists: {DATASET_ID}")
|
| 77 |
+
except Exception:
|
| 78 |
+
print(f"Creating new dataset: {DATASET_ID}")
|
| 79 |
+
api.create_repo(
|
| 80 |
+
repo_id=DATASET_ID.split("/")[1],
|
| 81 |
+
repo_type="dataset",
|
| 82 |
+
public=True,
|
| 83 |
+
exist_ok=True
|
| 84 |
+
)
|
| 85 |
+
print(f"Dataset created: {DATASET_ID}")
|
| 86 |
+
|
| 87 |
+
# Create README for the dataset
|
| 88 |
+
readme_content = """---
|
| 89 |
+
title: StyleForge CUDA Kernels
|
| 90 |
+
license: mit
|
| 91 |
+
tags:
|
| 92 |
+
- cuda
|
| 93 |
+
- neural-style-transfer
|
| 94 |
+
- styleforge
|
| 95 |
+
---
|
| 96 |
+
|
| 97 |
+
# StyleForge Pre-compiled CUDA Kernels
|
| 98 |
+
|
| 99 |
+
This repository contains pre-compiled CUDA kernels for the StyleForge neural style transfer project.
|
| 100 |
+
|
| 101 |
+
## Files
|
| 102 |
+
|
| 103 |
+
"""
|
| 104 |
+
for f in kernel_files:
|
| 105 |
+
readme_content += f"- `{f.name}`\n"
|
| 106 |
+
|
| 107 |
+
readme_content += """
|
| 108 |
+
## Usage
|
| 109 |
+
|
| 110 |
+
These kernels are automatically downloaded by StyleForge when running on Hugging Face Spaces.
|
| 111 |
+
|
| 112 |
+
## Compilation
|
| 113 |
+
|
| 114 |
+
Kernels are compiled for multiple GPU architectures:
|
| 115 |
+
- sm_70 (V100)
|
| 116 |
+
- sm_75 (T4)
|
| 117 |
+
- sm_80 (A100)
|
| 118 |
+
|
| 119 |
+
For local compilation, see `compile_kernels.py` in the main repository.
|
| 120 |
+
"""
|
| 121 |
+
|
| 122 |
+
# Upload files
|
| 123 |
+
print("Uploading files...")
|
| 124 |
+
|
| 125 |
+
# Upload README
|
| 126 |
+
api.upload_file(
|
| 127 |
+
path_or_fileobj=readme_content.encode(),
|
| 128 |
+
path_in_repo="README.md",
|
| 129 |
+
repo_id=DATASET_ID,
|
| 130 |
+
repo_type="dataset",
|
| 131 |
+
commit_message="Add dataset README"
|
| 132 |
+
)
|
| 133 |
+
print(" Uploaded: README.md")
|
| 134 |
+
|
| 135 |
+
# Upload kernel files
|
| 136 |
+
for kernel_file in kernel_files:
|
| 137 |
+
print(f" Uploading {kernel_file.name}...", end=" ", flush=True)
|
| 138 |
+
api.upload_file(
|
| 139 |
+
path_or_fileobj=str(kernel_file),
|
| 140 |
+
path_in_repo=kernel_file.name,
|
| 141 |
+
repo_id=DATASET_ID,
|
| 142 |
+
repo_type="dataset",
|
| 143 |
+
commit_message=f"Add {kernel_file.name}"
|
| 144 |
+
)
|
| 145 |
+
print("✓")
|
| 146 |
+
|
| 147 |
+
print()
|
| 148 |
+
print("=" * 60)
|
| 149 |
+
print("Upload complete!")
|
| 150 |
+
print("=" * 60)
|
| 151 |
+
print()
|
| 152 |
+
print(f"Dataset URL: https://huggingface.co/datasets/{DATASET_ID}")
|
| 153 |
+
print()
|
| 154 |
+
print("The kernels will be automatically downloaded by StyleForge")
|
| 155 |
+
print("when running on Hugging Face Spaces.")
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
if __name__ == "__main__":
|
| 159 |
+
upload_kernels()
|