Compare commits

...
Sign in to create a new pull request.

6 commits

Author SHA1 Message Date
Manan17
5c4ff32efc gpt comments 2026-03-16 23:58:15 +00:00
Manan Shah
76148ad344
Merge branch 'main' into feat/gguf-only-cpu 2026-03-16 18:18:04 -05:00
Manan Shah
d6ab972a19
Merge branch 'main' into feat/gguf-only-cpu 2026-03-16 18:09:09 -05:00
Manan17
f5b90c6392 resolving 2026-03-16 23:08:22 +00:00
pre-commit-ci[bot]
16d9113a6b [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-03-16 21:26:24 +00:00
Manan17
c2cd02dc8f GGUF chat only for CPU 2026-03-16 21:14:53 +00:00
6 changed files with 25 additions and 12 deletions

View file

@ -3,7 +3,7 @@
"""Default model lists for inference, split by platform."""
import sys
import utils.hardware.hardware as hw
DEFAULT_MODELS_GGUF = [
"unsloth/Llama-3.2-1B-Instruct-GGUF",
@ -25,6 +25,7 @@ DEFAULT_MODELS_STANDARD = [
def get_default_models() -> list[str]:
if sys.platform == "darwin":
hw.get_device() # ensure detect_hardware() has run
if hw.CHAT_ONLY:
return list(DEFAULT_MODELS_GGUF)
return list(DEFAULT_MODELS_STANDARD)

View file

@ -148,11 +148,14 @@ async def health_check():
platform_map = {"darwin": "mac", "win32": "windows", "linux": "linux"}
device_type = platform_map.get(sys.platform, sys.platform)
chat_only = _hw_module.CHAT_ONLY
return {
"status": "healthy",
"timestamp": datetime.now().isoformat(),
"service": "Unsloth UI Backend",
"device_type": device_type,
"chat_only": chat_only,
}

View file

@ -8,6 +8,7 @@ Hardware detection and GPU utilities
from .hardware import (
DeviceType,
DEVICE,
CHAT_ONLY,
detect_hardware,
get_device,
is_apple_silicon,
@ -24,6 +25,7 @@ from .hardware import (
__all__ = [
"DeviceType",
"DEVICE",
"CHAT_ONLY",
"detect_hardware",
"get_device",
"is_apple_silicon",

View file

@ -39,6 +39,7 @@ class DeviceType(str, Enum):
# ========== Global State (set once by detect_hardware) ==========
DEVICE: Optional[DeviceType] = None
CHAT_ONLY: bool = True # No CUDA GPU → GGUF chat only (Mac, CPU-only, etc.)
# ========== Detection ==========
@ -81,7 +82,8 @@ def detect_hardware() -> DeviceType:
2. MLX (Apple Silicon via MLX framework)
3. CPU (fallback)
"""
global DEVICE
global DEVICE, CHAT_ONLY
CHAT_ONLY = True # reset — only CUDA sets it to False
# --- CUDA: try PyTorch ---
if _has_torch():
@ -89,6 +91,7 @@ def detect_hardware() -> DeviceType:
if torch.cuda.is_available():
DEVICE = DeviceType.CUDA
CHAT_ONLY = False
device_name = torch.cuda.get_device_properties(0).name
print(f"Hardware detected: CUDA — {device_name}")
return DEVICE

View file

@ -396,9 +396,12 @@ export function HubModelPicker({
return s;
}, [cachedGguf, cachedModels]);
const chatOnly = usePlatformStore((s) => s.isChatOnly());
const recommendedIds = useMemo(() => {
const all = dedupe([...models.map((model) => model.id), value ?? ""])
.filter((id) => !downloadedSet.has(id.toLowerCase()));
.filter((id) => !downloadedSet.has(id.toLowerCase()))
.filter((id) => !chatOnly || isGgufRepo(id));
// Cap at 4 GGUFs + 4 non-GGUFs so the list stays manageable
const gguf: string[] = [];
const hub: string[] = [];
@ -407,7 +410,7 @@ export function HubModelPicker({
else if (!isGgufRepo(id) && hub.length < 4) hub.push(id);
}
return [...gguf, ...hub];
}, [models, value, downloadedSet]);
}, [models, value, downloadedSet, chatOnly]);
const { paramCountById: recommendedParamCountById } =
useRecommendedModelVram(recommendedIds);
@ -415,8 +418,6 @@ export function HubModelPicker({
const showHfSection = debouncedQuery.trim().length > 0;
const recommendedSet = useMemo(() => new Set(recommendedIds), [recommendedIds]);
const chatOnly = usePlatformStore((s) => s.isChatOnly());
const hfIds = useMemo(() => {
if (!showHfSection) return [];
return results
@ -519,7 +520,7 @@ export function HubModelPicker({
<Spinner className="size-3 text-muted-foreground" />
<span className="text-xs text-muted-foreground">Loading models</span>
</div>
) : !showHfSection && (cachedGguf.length > 0 || cachedModels.length > 0) ? (
) : !showHfSection && (cachedGguf.length > 0 || (!chatOnly && cachedModels.length > 0)) ? (
<>
<ListLabel>{"\uD83E\uDDA5"} Downloaded</ListLabel>
{cachedGguf.map((c) => (
@ -536,7 +537,7 @@ export function HubModelPicker({
)}
</div>
))}
{cachedModels.map((c) => (
{!chatOnly && cachedModels.map((c) => (
<ModelRow
key={c.repo_id}
label={c.repo_id}

View file

@ -16,14 +16,16 @@ export type DeviceType = "mac" | "windows" | "linux" | string;
interface PlatformState {
deviceType: DeviceType;
chatOnly: boolean;
fetched: boolean;
isChatOnly: () => boolean;
}
export const usePlatformStore = create<PlatformState>()((_, get) => ({
deviceType: "linux",
chatOnly: false,
fetched: false,
isChatOnly: () => get().deviceType === "mac",
isChatOnly: () => get().chatOnly,
}));
export async function fetchDeviceType(): Promise<DeviceType> {
@ -33,9 +35,10 @@ export async function fetchDeviceType(): Promise<DeviceType> {
try {
const res = await fetch("/api/health");
if (res.ok) {
const data = (await res.json()) as { device_type?: string };
const data = (await res.json()) as { device_type?: string; chat_only?: boolean };
const deviceType = data.device_type ?? "linux";
usePlatformStore.setState({ deviceType, fetched: true });
const chatOnly = data.chat_only ?? deviceType === "mac";
usePlatformStore.setState({ deviceType, chatOnly, fetched: true });
return deviceType;
}
} catch (err) {