Compare commits
2 Commits
fix/dashbo
...
feature/da
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab60962d76 | ||
| 201f4266b2 |
169
dashboard/src/app/api/chat/route.ts
Normal file
169
dashboard/src/app/api/chat/route.ts
Normal file
@@ -0,0 +1,169 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getLlamaContainerName } from "@/lib/docker";
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
export const maxDuration = 300;
|
||||
|
||||
/**
|
||||
* POST /api/chat
|
||||
*
|
||||
* Streams a chat completion from llama.cpp /v1/chat/completions (OpenAI-compatible).
|
||||
*
|
||||
* Body: {
|
||||
* messages: [{role, content}],
|
||||
* temperature?, top_p?, top_k?, min_p?, repeat_penalty?, max_tokens?, stream?
|
||||
* }
|
||||
*
|
||||
* Returns: SSE stream of OpenAI-compatible chat completion chunks.
|
||||
*/
|
||||
interface ChatMessage {
|
||||
role: "system" | "user" | "assistant";
|
||||
content: string;
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = (await req.json()) as {
|
||||
messages: ChatMessage[];
|
||||
temperature?: number;
|
||||
top_p?: number;
|
||||
top_k?: number;
|
||||
min_p?: number;
|
||||
repeat_penalty?: number;
|
||||
max_tokens?: number;
|
||||
stream?: boolean;
|
||||
};
|
||||
|
||||
if (!body.messages || !Array.isArray(body.messages) || body.messages.length === 0) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "messages array is required" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const containerName = await getLlamaContainerName();
|
||||
if (!containerName) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "llama container not running" },
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
|
||||
// Build the request payload for llama.cpp /v1/chat/completions endpoint.
|
||||
// llama.cpp supports OpenAI-compatible API.
|
||||
const payload: Record<string, unknown> = {
|
||||
messages: body.messages,
|
||||
stream: body.stream !== false,
|
||||
};
|
||||
if (body.temperature != null) payload.temperature = body.temperature;
|
||||
if (body.top_p != null) payload.top_p = body.top_p;
|
||||
if (body.top_k != null) payload.top_k = body.top_k;
|
||||
if (body.min_p != null) payload.min_p = body.min_p;
|
||||
if (body.repeat_penalty != null) payload.repeat_penalty = body.repeat_penalty;
|
||||
if (body.max_tokens != null) payload.max_tokens = body.max_tokens;
|
||||
|
||||
const payloadJson = JSON.stringify(payload);
|
||||
|
||||
// Build the docker exec command to send the request to llama.cpp inside
|
||||
// the container. We use `docker exec ... wget` because we can't reach
|
||||
// the container's port from the dashboard directly (different network
|
||||
// namespace). Actually — the dashboard IS on the same Docker network,
|
||||
// so we can just fetch http://llama:8080/v1/chat/completions directly.
|
||||
// But wget is more reliable for streaming.
|
||||
|
||||
const useStream = body.stream !== false;
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
if (useStream) {
|
||||
const stream = new ReadableStream<Uint8Array>({
|
||||
async start(controller) {
|
||||
try {
|
||||
// Use Node's fetch (available in Node 18+) to call llama.cpp
|
||||
// directly over the Docker network. The dashboard container is
|
||||
// on the same network as llama, so http://llama:8080 works.
|
||||
const res = await fetch("http://llama:8080/v1/chat/completions", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: payloadJson,
|
||||
signal: req.signal,
|
||||
});
|
||||
|
||||
if (!res.ok || !res.body) {
|
||||
const text = await res.text().catch(() => "");
|
||||
controller.enqueue(
|
||||
encoder.encode(
|
||||
`data: ${JSON.stringify({
|
||||
error: `llama returned ${res.status}: ${text.slice(0, 500)}`,
|
||||
})}\n\n`
|
||||
)
|
||||
);
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Pipe the response through — llama.cpp /v1/chat/completions with
|
||||
// stream=true returns SSE chunks (data: {...}\n\n).
|
||||
const reader = res.body.getReader();
|
||||
const pump = (): Promise<void> =>
|
||||
reader.read().then(({ done, value }) => {
|
||||
if (done) {
|
||||
controller.enqueue(encoder.encode("data: [DONE]\n\n"));
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
controller.enqueue(value);
|
||||
return pump();
|
||||
});
|
||||
await pump();
|
||||
} catch (err) {
|
||||
try {
|
||||
controller.enqueue(
|
||||
encoder.encode(
|
||||
`data: ${JSON.stringify({
|
||||
error: (err as Error).message,
|
||||
})}\n\n`
|
||||
)
|
||||
);
|
||||
controller.close();
|
||||
} catch {
|
||||
/* already closed */
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return new Response(stream, {
|
||||
headers: {
|
||||
"Content-Type": "text/event-stream; charset=utf-8",
|
||||
"Cache-Control": "no-cache, no-transform",
|
||||
"Connection": "keep-alive",
|
||||
"X-Accel-Buffering": "no",
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// Non-streaming — return JSON
|
||||
try {
|
||||
const res = await fetch("http://llama:8080/v1/chat/completions", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: payloadJson,
|
||||
});
|
||||
const text = await res.text();
|
||||
return new Response(text, {
|
||||
status: res.status,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
} catch (err) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: (err as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Suppress unused warning
|
||||
void spawn;
|
||||
@@ -10,6 +10,53 @@ import {
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
/**
|
||||
* Merge a Partial<DashboardConfig> into a full DashboardConfig. All known
|
||||
* fields are copied; missing fields keep their existing values.
|
||||
*/
|
||||
function mergeConfig(
|
||||
base: DashboardConfig,
|
||||
patch: Partial<DashboardConfig> | undefined
|
||||
): DashboardConfig {
|
||||
if (!patch) return base;
|
||||
return {
|
||||
model: patch.model ?? base.model,
|
||||
ctxSize: patch.ctxSize ?? base.ctxSize,
|
||||
parallel: patch.parallel ?? base.parallel,
|
||||
nGpuLayers: patch.nGpuLayers ?? base.nGpuLayers,
|
||||
threads: patch.threads ?? base.threads,
|
||||
draftModel: patch.draftModel ?? base.draftModel,
|
||||
specType: patch.specType ?? base.specType,
|
||||
specDraftNMax: patch.specDraftNMax ?? base.specDraftNMax,
|
||||
batchSize: patch.batchSize ?? base.batchSize,
|
||||
ubatchSize: patch.ubatchSize ?? base.ubatchSize,
|
||||
contextOverflow: patch.contextOverflow ?? base.contextOverflow,
|
||||
cacheTypeK: patch.cacheTypeK ?? base.cacheTypeK,
|
||||
cacheTypeV: patch.cacheTypeV ?? base.cacheTypeV,
|
||||
defragThold: patch.defragThold ?? base.defragThold,
|
||||
flashAttn: patch.flashAttn ?? base.flashAttn,
|
||||
noMmap: patch.noMmap ?? base.noMmap,
|
||||
mlock: patch.mlock ?? base.mlock,
|
||||
contBatching: patch.contBatching ?? base.contBatching,
|
||||
embeddings: patch.embeddings ?? base.embeddings,
|
||||
metrics: patch.metrics ?? base.metrics,
|
||||
ropeFreqScale: patch.ropeFreqScale ?? base.ropeFreqScale,
|
||||
ropeScale: patch.ropeScale ?? base.ropeScale,
|
||||
yarnExtFactor: patch.yarnExtFactor ?? base.yarnExtFactor,
|
||||
yarnAttnFactor: patch.yarnAttnFactor ?? base.yarnAttnFactor,
|
||||
yarnBetaFast: patch.yarnBetaFast ?? base.yarnBetaFast,
|
||||
yarnBetaSlow: patch.yarnBetaSlow ?? base.yarnBetaSlow,
|
||||
systemPrompt: patch.systemPrompt ?? base.systemPrompt,
|
||||
topK: patch.topK ?? base.topK,
|
||||
topP: patch.topP ?? base.topP,
|
||||
minP: patch.minP ?? base.minP,
|
||||
temperature: patch.temperature ?? base.temperature,
|
||||
repeatPenalty: patch.repeatPenalty ?? base.repeatPenalty,
|
||||
extraArgs: patch.extraArgs ?? base.extraArgs,
|
||||
presets: patch.presets ?? base.presets,
|
||||
};
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
const config = await loadConfig();
|
||||
return NextResponse.json({ config, defaults: DEFAULT_CONFIG });
|
||||
@@ -18,23 +65,7 @@ export async function GET() {
|
||||
export async function PUT(req: NextRequest) {
|
||||
const body = (await req.json()) as Partial<DashboardConfig>;
|
||||
const current = await loadConfig();
|
||||
|
||||
// Merge: keep existing presets unless explicitly overwritten
|
||||
const next: DashboardConfig = {
|
||||
model: body.model ?? current.model,
|
||||
ctxSize: body.ctxSize ?? current.ctxSize,
|
||||
parallel: body.parallel ?? current.parallel,
|
||||
nGpuLayers: body.nGpuLayers ?? current.nGpuLayers,
|
||||
threads: body.threads ?? current.threads,
|
||||
draftModel: body.draftModel ?? current.draftModel,
|
||||
specType: body.specType ?? current.specType,
|
||||
specDraftNMax: body.specDraftNMax ?? current.specDraftNMax,
|
||||
batchSize: body.batchSize ?? current.batchSize,
|
||||
contextOverflow: body.contextOverflow ?? current.contextOverflow,
|
||||
extraArgs: body.extraArgs ?? current.extraArgs,
|
||||
presets: body.presets ?? current.presets,
|
||||
};
|
||||
|
||||
const next = mergeConfig(current, body);
|
||||
await saveConfig(next);
|
||||
return NextResponse.json({ config: next });
|
||||
}
|
||||
@@ -46,9 +77,17 @@ export async function POST(req: NextRequest) {
|
||||
action: "save-preset" | "delete-preset" | "load-preset" | "reset";
|
||||
name?: string;
|
||||
id?: string;
|
||||
config?: Partial<DashboardConfig>;
|
||||
};
|
||||
const current = await loadConfig();
|
||||
|
||||
// If the caller passed a `config` in the body, merge it into `current`
|
||||
// before performing the action. This is critical for `save-preset`: if the
|
||||
// user has edited the form but not clicked "Apply" yet, the persisted
|
||||
// config.json still has the old values, and saving a preset would snapshot
|
||||
// the OLD config — not what's currently in the UI.
|
||||
const effective = mergeConfig(current, body.config);
|
||||
|
||||
if (body.action === "save-preset") {
|
||||
if (!body.name) {
|
||||
return NextResponse.json(
|
||||
@@ -59,12 +98,15 @@ export async function POST(req: NextRequest) {
|
||||
const preset: Preset = {
|
||||
id: `preset-${Date.now()}`,
|
||||
name: body.name,
|
||||
config: stripPresets(current),
|
||||
config: stripPresets(effective),
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
const next: DashboardConfig = {
|
||||
...current,
|
||||
presets: [...current.presets.filter((p) => p.name !== body.name), preset],
|
||||
...effective,
|
||||
presets: [
|
||||
...effective.presets.filter((p) => p.name !== body.name),
|
||||
preset,
|
||||
],
|
||||
};
|
||||
await saveConfig(next);
|
||||
return NextResponse.json({ config: next });
|
||||
|
||||
45
dashboard/src/app/api/metrics/route.ts
Normal file
45
dashboard/src/app/api/metrics/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
/**
|
||||
* GET /api/metrics
|
||||
*
|
||||
* Proxies llama.cpp's /metrics (Prometheus) endpoint. The dashboard container
|
||||
* is on the same Docker network as llama, so http://llama:8080/metrics works.
|
||||
*
|
||||
* Returns plain text (Prometheus exposition format).
|
||||
*/
|
||||
export async function GET() {
|
||||
try {
|
||||
const res = await fetch("http://llama:8080/metrics", {
|
||||
cache: "no-store",
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
if (!res.ok) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
ok: false,
|
||||
error: `llama returned ${res.status}`,
|
||||
raw: await res.text().catch(() => ""),
|
||||
},
|
||||
{ status: res.status }
|
||||
);
|
||||
}
|
||||
const text = await res.text();
|
||||
// Return as plain text — the frontend can render it as <pre>
|
||||
return new Response(text, {
|
||||
headers: { "Content-Type": "text/plain; version=0.0.4; charset=utf-8" },
|
||||
});
|
||||
} catch (err) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
ok: false,
|
||||
error: (err as Error).message,
|
||||
hint: "llama container must be running and started with --metrics flag",
|
||||
},
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
}
|
||||
51
dashboard/src/app/api/slots/route.ts
Normal file
51
dashboard/src/app/api/slots/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
/**
|
||||
* GET /api/slots
|
||||
*
|
||||
* Returns llama.cpp slot status from /slots endpoint. Each slot is one
|
||||
* parallel processing unit (controlled by --parallel). Includes:
|
||||
* - id: slot id (0-indexed)
|
||||
* - is_processing: bool
|
||||
* - prompt: current prompt tokens
|
||||
* - n_ctx: context size
|
||||
* - n_past: tokens processed so far
|
||||
* - n_eval: total tokens generated in this slot
|
||||
* - timings: { prompt_n, prompt_ms, prompt_per_token, prompt_per_second,
|
||||
* predicted_n, predicted_ms, predicted_per_token,
|
||||
* predicted_per_second }
|
||||
*
|
||||
* From these we can compute TPS (predicted_per_second), TTFT (prompt_ms),
|
||||
* cache-hit ratio, etc.
|
||||
*/
|
||||
export async function GET() {
|
||||
try {
|
||||
const res = await fetch("http://llama:8080/slots", {
|
||||
cache: "no-store",
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
if (!res.ok) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
ok: false,
|
||||
error: `llama returned ${res.status}`,
|
||||
},
|
||||
{ status: res.status }
|
||||
);
|
||||
}
|
||||
const data = await res.json();
|
||||
return NextResponse.json({ ok: true, slots: data });
|
||||
} catch (err) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
ok: false,
|
||||
error: (err as Error).message,
|
||||
slots: [],
|
||||
},
|
||||
{ status: 503 }
|
||||
);
|
||||
}
|
||||
}
|
||||
27
dashboard/src/app/icon.svg
Normal file
27
dashboard/src/app/icon.svg
Normal file
@@ -0,0 +1,27 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32" height="32">
|
||||
<defs>
|
||||
<linearGradient id="g" x1="0" y1="0" x2="32" y2="32" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#0a0a0a"/>
|
||||
<stop offset="1" stop-color="#525252"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="32" height="32" rx="6" fill="url(#g)"/>
|
||||
<!-- stylized "GPU" / chip icon -->
|
||||
<g fill="none" stroke="#fafafa" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect x="9" y="9" width="14" height="14" rx="2"/>
|
||||
<rect x="13" y="13" width="6" height="6" rx="0.5" fill="#fafafa" stroke="none"/>
|
||||
<!-- pins -->
|
||||
<line x1="12" y1="6" x2="12" y2="9"/>
|
||||
<line x1="16" y1="6" x2="16" y2="9"/>
|
||||
<line x1="20" y1="6" x2="20" y2="9"/>
|
||||
<line x1="12" y1="23" x2="12" y2="26"/>
|
||||
<line x1="16" y1="23" x2="16" y2="26"/>
|
||||
<line x1="20" y1="23" x2="20" y2="26"/>
|
||||
<line x1="6" y1="12" x2="9" y2="12"/>
|
||||
<line x1="6" y1="16" x2="9" y2="16"/>
|
||||
<line x1="6" y1="20" x2="9" y2="20"/>
|
||||
<line x1="23" y1="12" x2="26" y2="12"/>
|
||||
<line x1="23" y1="16" x2="26" y2="16"/>
|
||||
<line x1="23" y1="20" x2="26" y2="20"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
File diff suppressed because it is too large
Load Diff
@@ -194,10 +194,54 @@ export interface DashboardConfig {
|
||||
specType: "none" | "draft-mtp" | "draft-llama";
|
||||
/** Max draft tokens */
|
||||
specDraftNMax: number;
|
||||
/** Batch size */
|
||||
/** Batch size (prompt processing batch) */
|
||||
batchSize: number;
|
||||
/** Micro-batch size (physical batch on GPU) */
|
||||
ubatchSize: number;
|
||||
/** UB / KV cache size etc */
|
||||
contextOverflow: "none" | "shift" | "evict";
|
||||
/** KV cache type for K */
|
||||
cacheTypeK: "f16" | "f32" | "q8_0" | "q4_0";
|
||||
/** KV cache type for V */
|
||||
cacheTypeV: "f16" | "f32" | "q8_0" | "q4_0";
|
||||
/** KV cache defragmentation threshold (0..1) */
|
||||
defragThold: number;
|
||||
/** Enable Flash Attention */
|
||||
flashAttn: boolean;
|
||||
/** Don't mmap model (load to RAM) */
|
||||
noMmap: boolean;
|
||||
/** Lock model in RAM (prevents swap) */
|
||||
mlock: boolean;
|
||||
/** Continuous batching */
|
||||
contBatching: boolean;
|
||||
/** Enable /embeddings endpoint */
|
||||
embeddings: boolean;
|
||||
/** Enable /metrics (Prometheus) endpoint */
|
||||
metrics: boolean;
|
||||
/** RoPE frequency scale (NTK-aware, 1.0 = default) */
|
||||
ropeFreqScale: number;
|
||||
/** RoPE context scaling factor (1.0 = default) */
|
||||
ropeScale: number;
|
||||
/** YaRN extrapolation factor (1.0 = default) */
|
||||
yarnExtFactor: number;
|
||||
/** YaRN attention factor (1.0 = default) */
|
||||
yarnAttnFactor: number;
|
||||
/** YaRN beta fast (32.0 = default) */
|
||||
yarnBetaFast: number;
|
||||
/** YaRN beta slow (1.0 = default) */
|
||||
yarnBetaSlow: number;
|
||||
/** Default system prompt for chat completions (empty = none) */
|
||||
systemPrompt: string;
|
||||
/** Sampling: top-k (0 = disabled) */
|
||||
topK: number;
|
||||
/** Sampling: top-p (1.0 = disabled) */
|
||||
topP: number;
|
||||
/** Sampling: min-p (0 = disabled) */
|
||||
minP: number;
|
||||
/** Sampling: temperature (1.0 = default) */
|
||||
temperature: number;
|
||||
/** Sampling: repeat penalty (1.0 = disabled) */
|
||||
repeatPenalty: number;
|
||||
/** Free-form extra args (advanced) */
|
||||
extraArgs: string;
|
||||
/** Saved presets */
|
||||
@@ -221,7 +265,29 @@ export const DEFAULT_CONFIG: DashboardConfig = {
|
||||
specType: "none",
|
||||
specDraftNMax: 4,
|
||||
batchSize: 512,
|
||||
ubatchSize: 512,
|
||||
contextOverflow: "none",
|
||||
cacheTypeK: "f16",
|
||||
cacheTypeV: "f16",
|
||||
defragThold: 0.1,
|
||||
flashAttn: true,
|
||||
noMmap: false,
|
||||
mlock: false,
|
||||
contBatching: true,
|
||||
embeddings: false,
|
||||
metrics: false,
|
||||
ropeFreqScale: 1.0,
|
||||
ropeScale: 1.0,
|
||||
yarnExtFactor: 1.0,
|
||||
yarnAttnFactor: 1.0,
|
||||
yarnBetaFast: 32.0,
|
||||
yarnBetaSlow: 1.0,
|
||||
systemPrompt: "",
|
||||
topK: 40,
|
||||
topP: 0.95,
|
||||
minP: 0.05,
|
||||
temperature: 0.8,
|
||||
repeatPenalty: 1.1,
|
||||
extraArgs: "",
|
||||
presets: [],
|
||||
};
|
||||
@@ -316,6 +382,86 @@ export function parseLlamaExtraArgs(
|
||||
cfg.batchSize = Number(next) || cfg.batchSize;
|
||||
i++;
|
||||
break;
|
||||
case "--ubatch-size":
|
||||
case "-ub":
|
||||
cfg.ubatchSize = Number(next) || cfg.ubatchSize;
|
||||
i++;
|
||||
break;
|
||||
case "--cache-type-k":
|
||||
cfg.cacheTypeK = (next as DashboardConfig["cacheTypeK"]) || cfg.cacheTypeK;
|
||||
i++;
|
||||
break;
|
||||
case "--cache-type-v":
|
||||
cfg.cacheTypeV = (next as DashboardConfig["cacheTypeV"]) || cfg.cacheTypeV;
|
||||
i++;
|
||||
break;
|
||||
case "--defrag-thold":
|
||||
cfg.defragThold = Number(next) || cfg.defragThold;
|
||||
i++;
|
||||
break;
|
||||
case "--flash-attn":
|
||||
cfg.flashAttn = true;
|
||||
break;
|
||||
case "--no-mmap":
|
||||
cfg.noMmap = true;
|
||||
break;
|
||||
case "--mlock":
|
||||
cfg.mlock = true;
|
||||
break;
|
||||
case "--cont-batching":
|
||||
cfg.contBatching = true;
|
||||
break;
|
||||
case "--embeddings":
|
||||
cfg.embeddings = true;
|
||||
break;
|
||||
case "--metrics":
|
||||
cfg.metrics = true;
|
||||
break;
|
||||
case "--rope-freq-scale":
|
||||
cfg.ropeFreqScale = Number(next) || cfg.ropeFreqScale;
|
||||
i++;
|
||||
break;
|
||||
case "--rope-scaling":
|
||||
cfg.ropeScale = Number(next) || cfg.ropeScale;
|
||||
i++;
|
||||
break;
|
||||
case "--yarn-ext-factor":
|
||||
cfg.yarnExtFactor = Number(next) || cfg.yarnExtFactor;
|
||||
i++;
|
||||
break;
|
||||
case "--yarn-attn-factor":
|
||||
cfg.yarnAttnFactor = Number(next) || cfg.yarnAttnFactor;
|
||||
i++;
|
||||
break;
|
||||
case "--yarn-beta-fast":
|
||||
cfg.yarnBetaFast = Number(next) || cfg.yarnBetaFast;
|
||||
i++;
|
||||
break;
|
||||
case "--yarn-beta-slow":
|
||||
cfg.yarnBetaSlow = Number(next) || cfg.yarnBetaSlow;
|
||||
i++;
|
||||
break;
|
||||
case "--top-k":
|
||||
cfg.topK = Number(next);
|
||||
i++;
|
||||
break;
|
||||
case "--top-p":
|
||||
cfg.topP = Number(next);
|
||||
i++;
|
||||
break;
|
||||
case "--min-p":
|
||||
cfg.minP = Number(next);
|
||||
i++;
|
||||
break;
|
||||
case "--temp":
|
||||
case "--temperature":
|
||||
cfg.temperature = Number(next);
|
||||
i++;
|
||||
break;
|
||||
case "--repeat-penalty":
|
||||
cfg.repeatPenalty = Number(next);
|
||||
i++;
|
||||
break;
|
||||
case "--model-draft":
|
||||
cfg.draftModel = path.basename(next || "");
|
||||
i++;
|
||||
@@ -357,8 +503,35 @@ export function buildLlamaExtraArgs(cfg: DashboardConfig): string {
|
||||
if (cfg.nGpuLayers >= 0) parts.push(`--n-gpu-layers ${cfg.nGpuLayers}`);
|
||||
if (cfg.threads > 0) parts.push(`--threads ${cfg.threads}`);
|
||||
parts.push(`--batch-size ${cfg.batchSize}`);
|
||||
parts.push(`--ubatch-size ${cfg.ubatchSize}`);
|
||||
if (cfg.contextOverflow !== "none")
|
||||
parts.push(`--context-overflow ${cfg.contextOverflow}`);
|
||||
// KV cache types
|
||||
parts.push(`--cache-type-k ${cfg.cacheTypeK}`);
|
||||
parts.push(`--cache-type-v ${cfg.cacheTypeV}`);
|
||||
if (cfg.defragThold >= 0 && cfg.defragThold !== 0.1)
|
||||
parts.push(`--defrag-thold ${cfg.defragThold}`);
|
||||
// Performance flags
|
||||
if (cfg.flashAttn) parts.push("--flash-attn");
|
||||
if (cfg.noMmap) parts.push("--no-mmap");
|
||||
if (cfg.mlock) parts.push("--mlock");
|
||||
if (cfg.contBatching) parts.push("--cont-batching");
|
||||
if (cfg.embeddings) parts.push("--embeddings");
|
||||
if (cfg.metrics) parts.push("--metrics");
|
||||
// RoPE / YaRN
|
||||
if (cfg.ropeFreqScale !== 1.0)
|
||||
parts.push(`--rope-freq-scale ${cfg.ropeFreqScale}`);
|
||||
if (cfg.ropeScale !== 1.0)
|
||||
parts.push(`--rope-scaling ${cfg.ropeScale}`);
|
||||
if (cfg.yarnExtFactor !== 1.0)
|
||||
parts.push(`--yarn-ext-factor ${cfg.yarnExtFactor}`);
|
||||
if (cfg.yarnAttnFactor !== 1.0)
|
||||
parts.push(`--yarn-attn-factor ${cfg.yarnAttnFactor}`);
|
||||
if (cfg.yarnBetaFast !== 32.0)
|
||||
parts.push(`--yarn-beta-fast ${cfg.yarnBetaFast}`);
|
||||
if (cfg.yarnBetaSlow !== 1.0)
|
||||
parts.push(`--yarn-beta-slow ${cfg.yarnBetaSlow}`);
|
||||
// Speculative decoding
|
||||
if (cfg.specType !== "none") {
|
||||
parts.push(`--spec-type ${cfg.specType}`);
|
||||
if (cfg.draftModel) {
|
||||
@@ -366,6 +539,13 @@ export function buildLlamaExtraArgs(cfg: DashboardConfig): string {
|
||||
parts.push(`--spec-draft-n-max ${cfg.specDraftNMax}`);
|
||||
}
|
||||
}
|
||||
// Default sampling (server applies these as defaults for /completion)
|
||||
if (cfg.topK > 0) parts.push(`--top-k ${cfg.topK}`);
|
||||
if (cfg.topP < 1.0) parts.push(`--top-p ${cfg.topP}`);
|
||||
if (cfg.minP > 0) parts.push(`--min-p ${cfg.minP}`);
|
||||
if (cfg.temperature !== 1.0) parts.push(`--temp ${cfg.temperature}`);
|
||||
if (cfg.repeatPenalty > 1.0)
|
||||
parts.push(`--repeat-penalty ${cfg.repeatPenalty}`);
|
||||
if (cfg.extraArgs.trim()) parts.push(cfg.extraArgs.trim());
|
||||
return parts.join(" ");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user