Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,14 @@ export class LlamaCpp implements LLM {
* half the math cores, with at least 4 threads per context.
*/
private async computeParallelism(perContextMB: number): Promise<number> {
// QMD_MAX_PARALLEL_CONTEXTS: hard cap on context count.
// Set to 1 in MCP mode to prevent node-llama-cpp Metal deadlocks
// when multiple contexts call getEmbeddingFor/rankAll via Promise.all.
const maxOverride = parseInt(process.env.QMD_MAX_PARALLEL_CONTEXTS ?? "", 10);
if (Number.isFinite(maxOverride) && maxOverride > 0) {
return maxOverride;
}

const llama = await this.ensureLlama();

if (llama.gpu) {
Expand Down