GGUF
conversational
File size: 4,223 Bytes
145d474
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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()