Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(llm): add max_new_tokens parameter #10

Merged
merged 2 commits into from
Oct 22, 2024
Merged
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
28 changes: 21 additions & 7 deletions src/runs/execution/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import {
WATSONX_REGION
} from '@/config';

const MAX_NEW_TOKENS = 4096;

export function getDefaultModel(backend: LLMBackend = LLM_BACKEND) {
switch (backend) {
case LLMBackend.IBM_VLLM:
Expand Down Expand Up @@ -95,6 +97,10 @@ export function createChatLLM(run: Loaded<Run>, backend: LLMBackend = LLM_BACKEN
...parameters.sampling,
top_p: run.topP ?? parameters.sampling?.top_p,
temperature: run.temperature ?? parameters.sampling?.temperature
},
stopping: {
...parameters.stopping,
max_new_tokens: MAX_NEW_TOKENS
}
})
});
Expand All @@ -106,7 +112,8 @@ export function createChatLLM(run: Loaded<Run>, backend: LLMBackend = LLM_BACKEN
modelId: run.model,
parameters: {
top_p: run.topP,
temperature: run.temperature
temperature: run.temperature,
num_predict: MAX_NEW_TOKENS
}
});
}
Expand All @@ -117,7 +124,8 @@ export function createChatLLM(run: Loaded<Run>, backend: LLMBackend = LLM_BACKEN
modelId: run.model as OpenAI.ChatModel,
parameters: {
top_p: run.topP,
temperature: run.temperature
temperature: run.temperature,
max_completion_tokens: MAX_NEW_TOKENS
}
});
}
Expand All @@ -128,7 +136,8 @@ export function createChatLLM(run: Loaded<Run>, backend: LLMBackend = LLM_BACKEN
parameters: (parameters) => ({
...parameters,
top_p: run.topP ?? parameters.top_p,
temperature: run.temperature ?? parameters.temperature
temperature: run.temperature ?? parameters.temperature,
max_new_tokens: MAX_NEW_TOKENS
})
});
}
Expand All @@ -142,7 +151,8 @@ export function createChatLLM(run: Loaded<Run>, backend: LLMBackend = LLM_BACKEN
parameters: (parameters) => ({
...parameters,
top_p: run.topP ?? parameters.top_p,
temperature: run.temperature ?? parameters.temperature
temperature: run.temperature ?? parameters.temperature,
max_new_tokens: MAX_NEW_TOKENS
})
});
}
Expand All @@ -168,7 +178,10 @@ export function createCodeLLM(backend: LLMBackend = LLM_BACKEND) {
return new IBMvLLM({
client: vllmClient,
modelId: 'ibm/granite-34b-code-instruct',
parameters: { method: 'GREEDY', stopping: { include_stop_sequence: false } }
parameters: {
method: 'GREEDY',
stopping: { include_stop_sequence: false, max_new_tokens: MAX_NEW_TOKENS }
}
});
}
case LLMBackend.BAM: {
Expand All @@ -178,7 +191,8 @@ export function createCodeLLM(backend: LLMBackend = LLM_BACKEND) {
modelId: 'ibm/granite-34b-code-instruct',
parameters: {
decoding_method: 'greedy',
include_stop_sequence: false
include_stop_sequence: false,
max_new_tokens: MAX_NEW_TOKENS
}
});
}
Expand All @@ -193,7 +207,7 @@ export function createCodeLLM(backend: LLMBackend = LLM_BACKEND) {
parameters: {
decoding_method: 'greedy',
include_stop_sequence: false,
max_new_tokens: 2048
max_new_tokens: MAX_NEW_TOKENS
}
});
}
Expand Down