Skip to content

Commit 82fd343

Browse files
V4.2.4: Use PyTorch CUDAExtension for proper nvcc CUDA compilation
1 parent 5274d65 commit 82fd343

File tree

4 files changed

+180
-222
lines changed

4 files changed

+180
-222
lines changed

Crayon_Colab_Notebook.py

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
XERV CRAYON V4.2.3 - Omni-Backend Tokenizer
2+
XERV CRAYON V4.2.4 - Omni-Backend Tokenizer
33
=============================================
44
Copy this ENTIRE script into a Google Colab cell and run it.
55
@@ -13,11 +13,11 @@
1313
import time
1414

1515
print("=" * 70)
16-
print("XERV CRAYON INSTALLATION V4.2.3")
16+
print("XERV CRAYON INSTALLATION V4.2.4")
1717
print("=" * 70)
1818

1919
# Step 1: GPU Detection
20-
print("\n[1/6] Detecting GPU hardware...")
20+
print("\n[1/7] Detecting GPU hardware...")
2121
try:
2222
result = subprocess.run(["nvidia-smi", "--query-gpu=name,compute_cap", "--format=csv,noheader"],
2323
capture_output=True, text=True, timeout=10)
@@ -33,72 +33,79 @@
3333
has_gpu = False
3434

3535
# Step 2: NVCC Detection
36-
print("\n[2/6] Checking CUDA compiler...")
36+
print("\n[2/7] Checking CUDA compiler...")
3737
nvcc_check = subprocess.run(["which", "nvcc"], capture_output=True, text=True)
3838
if nvcc_check.returncode == 0:
3939
nvcc_path = nvcc_check.stdout.strip()
4040
print(f" NVCC: {nvcc_path}")
41-
nvcc_v = subprocess.run([nvcc_path, "--version"], capture_output=True, text=True)
42-
for line in nvcc_v.stdout.split("\n"):
43-
if "release" in line.lower():
44-
print(f" {line.strip()}")
4541
has_nvcc = True
4642
else:
4743
print(" NVCC not found")
4844
has_nvcc = False
4945

50-
# Step 3: Clean ALL Caches
51-
print("\n[3/6] Cleaning ALL caches...")
46+
# Step 3: Ensure PyTorch is installed (required for CUDAExtension)
47+
print("\n[3/7] Checking PyTorch...")
48+
try:
49+
import torch
50+
print(f" PyTorch {torch.__version__}")
51+
print(f" CUDA available: {torch.cuda.is_available()}")
52+
except ImportError:
53+
print(" Installing PyTorch...")
54+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "torch"])
55+
import torch
56+
print(f" PyTorch {torch.__version__} installed")
57+
58+
# Step 4: Clean ALL Caches
59+
print("\n[4/7] Cleaning ALL caches...")
5260
os.system("pip uninstall -y xerv-crayon crayon 2>/dev/null")
5361
os.system("pip cache purge 2>/dev/null")
54-
os.system("rm -rf /tmp/crayon /tmp/crayon_build ~/.cache/pip 2>/dev/null")
62+
os.system("rm -rf /tmp/crayon* ~/.cache/pip 2>/dev/null")
5563
print(" Done")
5664

57-
# Step 4: Fresh Clone with timestamp to avoid caching
58-
print("\n[4/6] Cloning from GitHub (fresh)...")
65+
# Step 5: Fresh Clone
66+
print("\n[5/7] Cloning from GitHub...")
5967
timestamp = int(time.time())
6068
clone_dir = f"/tmp/crayon_{timestamp}"
6169
os.system(f"git clone --depth 1 https://github.com/Electroiscoding/CRAYON.git {clone_dir}")
6270

63-
# Verify version in cloned repo
64-
version_check = subprocess.run(["grep", "__version__", f"{clone_dir}/src/crayon/__init__.py"],
71+
version_check = subprocess.run(["grep", "-m1", "__version__", f"{clone_dir}/src/crayon/__init__.py"],
6572
capture_output=True, text=True)
66-
print(f" Cloned version: {version_check.stdout.strip()}")
73+
print(f" {version_check.stdout.strip()}")
6774

68-
# Step 5: Install with verbose output and no cache
69-
print("\n[5/6] Building and installing...")
75+
# Step 6: Build and Install
76+
print("\n[6/7] Building with CUDA support (this takes ~2 min)...")
7077
print("-" * 70)
7178

79+
env = os.environ.copy()
80+
env["CUDA_HOME"] = "/usr/local/cuda"
81+
7282
result = subprocess.run(
7383
[sys.executable, "-m", "pip", "install", "-v", "--no-cache-dir", "--no-build-isolation", clone_dir],
74-
env={**os.environ, "CUDA_HOME": "/usr/local/cuda"}
84+
env=env
7585
)
7686

7787
print("-" * 70)
7888

79-
# Step 6: Verify Installation
80-
print("\n[6/6] Verifying installation...")
89+
# Step 7: Verify
90+
print("\n[7/7] Verifying installation...")
8191

82-
# Force reimport
83-
if "crayon" in sys.modules:
84-
del sys.modules["crayon"]
8592
for key in list(sys.modules.keys()):
86-
if key.startswith("crayon"):
93+
if "crayon" in key:
8794
del sys.modules[key]
8895

8996
import crayon
90-
print(f"\n Crayon Version: {crayon.get_version()}")
97+
print(f"\n Version: {crayon.get_version()}")
9198
backends = crayon.check_backends()
9299
print(f" Backends: {backends}")
93100

94101
if backends.get("cuda"):
95-
print(" CUDA backend: READY")
102+
print(" CUDA: READY", "\u2705")
96103
elif has_gpu and has_nvcc:
97-
print("\n WARNING: GPU + NVCC detected but CUDA backend not available!")
98-
print(" Check the build output above for errors.")
104+
print(" WARNING: GPU detected but CUDA not compiled!")
105+
print(" Check build output above for nvcc errors")
99106

100107
print("\n" + "=" * 70)
101-
print("INITIALIZATION")
108+
print("TOKENIZER TEST")
102109
print("=" * 70)
103110

104111
from crayon import CrayonVocab
@@ -107,24 +114,21 @@
107114
vocab.load_profile("lite")
108115

109116
info = vocab.get_info()
110-
print(f"\nActive Device: {info['device'].upper()}")
117+
print(f"\nDevice: {info['device'].upper()}")
111118
print(f"Backend: {info['backend']}")
112119
print(f"Vocabulary: {vocab.vocab_size:,} tokens")
113120

114-
# Quick test
115-
text = "Hello, Crayon tokenizer!"
121+
text = "Hello, Crayon!"
116122
tokens = vocab.tokenize(text)
117-
print(f"\nTest: '{text}' -> {len(tokens)} tokens")
123+
print(f"\nTest: '{text}' -> {tokens}")
118124

119125
print("\n" + "=" * 70)
120-
print("BENCHMARKS")
126+
print("BENCHMARKS")
121127
print("=" * 70)
122128

123-
import time
124-
125129
base_text = "The quick brown fox jumps over the lazy dog."
126130

127-
print("\n--- Batch Throughput ---")
131+
print("\n--- Throughput ---")
128132
for batch_size in [1000, 10000, 50000]:
129133
batch = [base_text] * batch_size
130134
vocab.tokenize(batch[:10])
@@ -135,14 +139,15 @@
135139
print(f"{batch_size:>8}: {batch_size/duration:>12,.0f} docs/sec | {total_tokens/duration:>14,.0f} tokens/sec")
136140

137141
if vocab.device != "cpu":
138-
print(f"\n--- GPU Stress Test ({vocab.device.upper()}) ---")
142+
print(f"\n--- GPU Stress Test ---")
139143
for batch_size in [100000, 500000]:
140144
batch = [base_text] * batch_size
141145
start = time.time()
142146
results = vocab.tokenize(batch)
143147
duration = time.time() - start
144-
total_tokens = sum(len(r) for r in results)
145148
print(f"{batch_size:>8}: {batch_size/duration:>12,.0f} docs/sec in {duration:.3f}s")
146149

147150
vocab.close()
148-
print("\nDone!")
151+
print("\n" + "=" * 70)
152+
print("DONE!")
153+
print("=" * 70)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "xerv-crayon"
7-
version = "4.2.3"
7+
version = "4.2.4"
88
description = "Omni-Backend Tokenizer - CPU (AVX2/512), CUDA (NVIDIA), ROCm (AMD) with automatic hardware detection"
99
readme = "README.md"
1010
requires-python = ">=3.10"

0 commit comments

Comments
 (0)