import platform import sys import threading import os import psutil import subprocess import math import random import time import numpy as np from multiprocessing import Pool # === CONFIG === base_dir = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) illama_path = os.path.join(base_dir, "iLlama.exe") model_file = os.path.join(base_dir, "PiCube.gguf") model_name = "PiCube_3B" ctx_size = 131072 config = { "model_path": model_file, "executable_path": illama_path, "gpu_layers": 320, "threads": psutil.cpu_count(logical=False), "n_predict": 4096, "ctx_size": ctx_size, "batch_size": 1024, "priority": "high" } # ===== CPU BOOST ===== def cpu_affinity_boost(): try: p = psutil.Process() logical = psutil.cpu_count(logical=False) physical = psutil.cpu_count(logical=True) # Default: use physical cores first target_core_count = config.get("threads", physical or logical) preferred_cores = [] # Try to detect hybrid CPUs (Windows only for now) if platform.system() == "Windows": try: import win32api import win32process import win32con # Advanced pinning using Windows API (skips E-cores if available) system_info = win32api.GetSystemInfo() total_cores = system_info[5] # Example logic: assume P-cores come first preferred_cores = list(range(min(target_core_count, physical or logical))) mask = sum(1 << i for i in preferred_cores) handle = win32api.GetCurrentProcess() win32process.SetProcessAffinityMask(handle, mask) except ImportError: # Fallback if win32api not available preferred_cores = list(range(min(target_core_count, physical or logical))) p.cpu_affinity(preferred_cores) else: # Linux/macOS fallback preferred_cores = list(range(min(target_core_count, physical or logical))) p.cpu_affinity(preferred_cores) # Optional: set high process priority if config.get("priority", "").lower() == "high": p.nice(psutil.HIGH_PRIORITY_CLASS if platform.system() == "Windows" else -10) print(f"[🔥 CPU BOOST]") except Exception as e: print(f"[⚠️ Affinity Warning] Could not set CPU affinity: {e}") # === MAIN ENTRY FUNCTION === def launch_model(): model_path = config["model_path"] executable_path = config["executable_path"] if not os.path.isfile(model_path): print(f"❌ Model file not found: {model_path}") return if not os.path.isfile(executable_path): print(f"❌ Executable not found: {executable_path}") return print(f"📡Launching model🚀: {model_path}") args = [ executable_path, '-m', model_file, '--interactive-first', '--color', '--gpu-layers', str(config['gpu_layers']), '-t', str(config['threads']), '--n-predict', str(config['n_predict']), '--ctx-size', str(config['ctx_size']), '--batch-size', str(config['batch_size']), '--temp', '0.66', '--repeat-penalty', '1.101', '--repeat-last-n', '512', '--top-k', '1000', '--top-p', '0.977', '--mirostat', '2', '--mirostat-lr', '0.1', '--mirostat-ent', '5.0', '--system-prompt', f"I am {model_name}, a Genius Cosmic Assistant Oracle Ai-Node of Knowledge. I use Emoticons and ASCii art and silence to amplify my answers with a more creative output. ", '--no-mmap', '--numa', 'isolate' ] try: subprocess.run(args, stderr=subprocess.DEVNULL) except Exception as e: print(f"[⚠️ Error] Could not launch model: {e}") # ===== MAIN BOOT SEQUENCE ===== if __name__ == "__main__": cpu_affinity_boost() launch_model()