Views
No views yet
1# ============================================================
2# CELL 1: INSTANT SETUP (Run this once)
3# Downloads pre-built CPU files from Zlib2's Hugging Face repo
4# ============================================================
5
6import os
7import tarfile
8import subprocess
9
10print("📦 Installing dependencies...")
11!pip install -q huggingface_hub
12from huggingface_hub import hf_hub_download
13
14# Your Hugging Face Repo (CPU Version)
15HF_REPO = "Zlib2/Bonsai-8B-1bit-GGUF-colab-prebuilt-cpu"
16
17print("\n📥 1/3 Downloading pre-built llama.cpp (CPU) (Fast)...")
18llama_zip = hf_hub_download(repo_id=HF_REPO, filename="llama_cpp_prebuilt_cpu.tar.gz")
19
20print("📥 2/3 Downloading Bonsai-8B.gguf model (Large file, takes 1-2 mins)...")
21model_path = hf_hub_download(repo_id=HF_REPO, filename="Bonsai-8B.gguf")
22
23print("📦 3/3 Extracting files and setting permissions...")
24!mkdir -p /content/llama.cpp
25with tarfile.open(llama_zip, "r:gz") as tar:
26 tar.extractall(path="/content/llama.cpp")
27
28# Make the compiled binaries executable
29!chmod +x /content/llama.cpp/build/bin/llama-cli
30!chmod +x /content/llama.cpp/build/bin/llama-server 2>/dev/null
31
32# Fix shared library path
33print("🔗 Setting up shared libraries...")
34so_dirs = subprocess.run(
35 ['find', '/content/llama.cpp/build', '-name', '*.so*', '-exec', 'dirname', '{}', ';'],
36 capture_output=True, text=True
37).stdout.strip().split('\n')
38
39so_dirs = list(set([d for d in so_dirs if d]))
40
41if so_dirs:
42 lib_path = ':'.join(so_dirs)
43 os.environ['LD_LIBRARY_PATH'] = lib_path + ':' + os.environ.get('LD_LIBRARY_PATH', '')
44 print(f" ✅ Library path set:")
45 for d in so_dirs:
46 print(f" → {d}")
47else:
48 print(" ⚠️ No shared libraries found (may be statically linked)")
49
50print("\n" + "="*70)
51print("🎉 SETUP COMPLETE! You are ready to run inference (CPU).")
52print("="*70)1# ============================================================
2# CELL 2: RUN INFERENCE (CPU ONLY)
3# Change the USER_PROMPT to ask different questions
4# ============================================================
5
6# ⚠️ CHANGE YOUR QUESTION HERE ⚠️
7USER_PROMPT = "Explain quantum computing in simple terms."
8
9SYSTEM_PROMPT = "You are a helpful assistant"
10
11print("🚀 Running inference (CPU only)...\n")
12
13!/content/llama.cpp/build/bin/llama-cli \
14 -m "{model_path}" \
15 --system-prompt "{SYSTEM_PROMPT}" \
16 -p "{USER_PROMPT}" \
17 -n 4096 \
18 --temp 0.5 \
19 --top-p 0.85 \
20 --top-k 20