Skip to content

Commit

Permalink
Merge pull request #59 from huggingface/max_new_tokens
Browse files Browse the repository at this point in the history
Support changing max new tokens setting
  • Loading branch information
mishig25 committed Aug 29, 2023
2 parents 8cc67d9 + 198a1a0 commit f044ff0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"publisher": "HuggingFace",
"name": "huggingface-vscode",
"version": "0.0.32",
"version": "0.0.33",
"displayName": "HF Code Autocomplete",
"description": "AI Autocomplete for OSS code-gen models",
"icon": "small_logo.png",
Expand Down Expand Up @@ -222,6 +222,11 @@
"default": 0.2,
"description": "Sampling temperature"
},
"HuggingFaceCode.maxNewTokens": {
"type": "integer",
"default": 60,
"description": "Max number of new tokens to be generated. The accepted range is [50-500] both ends inclusive. Be warned that the latency of a request will increase with higher number."
},
"HuggingFaceCode.stopTokens": {
"type": "array",
"items": {
Expand Down
12 changes: 9 additions & 3 deletions src/runCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default async function runCompletion(
const prefix = document.getText(new Range(beforeStart, position)) + currentSuggestionText;
const suffix = document.getText(new Range(position, afterEnd));

const config: HFCodeConfig = workspace.getConfiguration("HuggingFaceCode") as WorkspaceConfiguration & HFCodeConfig;
const { modelIdOrEndpoint, isFillMode, autoregressiveModeTemplate, fillModeTemplate, stopTokens, tokensToClear, temperature } = config;
const config = workspace.getConfiguration("HuggingFaceCode") as WorkspaceConfiguration & HFCodeConfig;
const { modelIdOrEndpoint, isFillMode, autoregressiveModeTemplate, fillModeTemplate, stopTokens, tokensToClear, temperature, maxNewTokens } = config;

const context = getTabnineExtensionContext();
const apiToken = await context?.secrets.get("apiToken");
Expand Down Expand Up @@ -61,7 +61,7 @@ export default async function runCompletion(
const data = {
inputs,
parameters: {
max_new_tokens: 60,
max_new_tokens: clipMaxNewTokens(maxNewTokens as number),
temperature,
do_sample: temperature > 0,
top_p: 0.95,
Expand Down Expand Up @@ -141,3 +141,9 @@ export function getFileNameWithExtension(document: TextDocument): string {
}
return fileName;
}

function clipMaxNewTokens(maxNewTokens: number): number {
const MIN = 50;
const MAX = 500;
return Math.min(Math.max(maxNewTokens, MIN), MAX);
}

0 comments on commit f044ff0

Please sign in to comment.