Skip to content

Commit

Permalink
fix: improve model downloader CI logs (#329)
Browse files Browse the repository at this point in the history
* fix: improve model downloader CI logs
* fix: `CodeGemma` adaptations
  • Loading branch information
giladgd authored Sep 22, 2024
1 parent ebc4e83 commit 4b7ef5b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 11 deletions.
24 changes: 20 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"filenamify": "^6.0.0",
"fs-extra": "^11.2.0",
"ignore": "^5.3.2",
"ipull": "^3.6.2",
"ipull": "^3.7.2",
"is-unicode-supported": "^2.1.0",
"lifecycle-utils": "^1.7.0",
"log-symbols": "^7.0.0",
Expand Down
8 changes: 5 additions & 3 deletions src/cli/recommendedModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ export const recommendedModels: ModelRecommendation[] = [{
name: "Mixtral 8x7B MoE",
abilities: ["chat", "complete"],
description: "Mixtral models were created by Mistal AI and are general purpose models that utilize a Mixture of Experts architecture.\n" +
"Mixtures of Experts (MoE) is a technique where different models, each skilled in solving a particular kind of problem, work together to the improve the overall performance on complex tasks.\n"
+ "This model includes 8 expert models, each with 7 billion parameters.",
"Mixtures of Experts (MoE) is a technique where different models, each skilled in solving a particular kind of problem, work together to the improve the overall performance on complex tasks.\n" +
"This model includes 8 expert models, each with 7 billion parameters.",

fileOptions: [{
huggingFace: {
Expand All @@ -178,7 +178,7 @@ export const recommendedModels: ModelRecommendation[] = [{
name: "Mistral 7B Instruct v0.2",
abilities: ["chat", "complete"],
description: "Mistral models were created by Mistal AI and are general purpose models.\n" +
+ "This is the 7 billion parameters version of the model.",
"This is the 7 billion parameters version of the model.",

fileOptions: [{
huggingFace: {
Expand Down Expand Up @@ -518,6 +518,7 @@ export const recommendedModels: ModelRecommendation[] = [{
abilities: ["code", "complete", "infill"],
description: "CodeGemma models were created by Google and are optimized for code completion, code generation, " +
"natual language understanding, mathematical reasoning, and instruction following.\n" +
"This model is not suited for chat.\n" +
"This is the 2 billion parameters version of the model.\n",

fileOptions: [{
Expand Down Expand Up @@ -556,6 +557,7 @@ export const recommendedModels: ModelRecommendation[] = [{
abilities: ["code", "complete", "infill"],
description: "CodeGemma models were created by Google and are optimized for code completion, code generation, " +
"natual language understanding, mathematical reasoning, and instruction following.\n" +
"This model is not suited for chat.\n" +
"This is the 7 billion parameters version of the model.\n",

fileOptions: [{
Expand Down
25 changes: 24 additions & 1 deletion src/evaluator/LlamaCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ export class LlamaCompletion {
const bosToken = this._sequence.model.tokens.bos;
const shouldPrependBosToken = this._sequence.model.tokens.shouldPrependBosToken;

const extraEosTokens = getExtraCompletionEosTokens(this._sequence.model);

async function fitInputIntoContext({
maxTokens, tokens
}: {
Expand Down Expand Up @@ -348,7 +350,8 @@ export class LlamaCompletion {
tokens: [...resolvedInput, ...res, ...pendingTokens]
})
};
}
},
extraEosTokens
});
});
}
Expand Down Expand Up @@ -840,6 +843,26 @@ async function resolveContextShiftSize(
return defaultContextShiftSize(sequence);
}

function getExtraCompletionEosTokens(model: LlamaModel) {
const extraEosTokens = new Set<Token>();

if (model.fileInfo.metadata?.general?.architecture === GgufArchitectureType.gemma ||
model.fileInfo.metadata?.general?.architecture === GgufArchitectureType.gemma2
) {
for (const token of model.iterateAllTokens()) {
const tokenText = model.detokenize([token], true);
if (tokenText === "<|file_separator|>" || tokenText === "<|fim_prefix|>") {
extraEosTokens.add(token);

if (extraEosTokens.size === 2)
break;
}
}
}

return extraEosTokens;
}

function getExtraInfillEosTokens(model: LlamaModel) {
const extraEosTokens = new Set<Token>();

Expand Down
6 changes: 5 additions & 1 deletion src/utils/createModelDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from "fs-extra";
import {normalizeGgufDownloadUrl} from "../gguf/utils/normalizeGgufDownloadUrl.js";
import {createSplitPartFilename, resolveSplitGgufParts} from "../gguf/utils/resolveSplitGgufParts.js";
import {getFilenameForBinarySplitGgufPartUrls, resolveBinarySplitGgufPartUrls} from "../gguf/utils/resolveBinarySplitGgufPartUrls.js";
import {cliModelsDirectory} from "../config.js";
import {cliModelsDirectory, isCI} from "../config.js";
import {safeEventCallback} from "./safeEventCallback.js";
import {ModelFileAccessTokens, resolveModelFileAccessTokensTryHeaders} from "./modelFileAccesTokens.js";
import {pushAll} from "./pushAll.js";
Expand Down Expand Up @@ -312,6 +312,7 @@ export class ModelDownloader {
directory: this._dirPath,
fileName: this._fileName ?? getFilenameForBinarySplitGgufPartUrls(binarySplitPartUrls),
cliProgress: this._showCliProgress,
cliStyle: isCI ? "ci" : "fancy",
headers: this._headers ?? {},
tryHeaders: this._tryHeaders.slice(),
skipExisting: this._skipExisting
Expand All @@ -335,6 +336,7 @@ export class ModelDownloader {
directory: this._dirPath,
fileName: this._fileName ?? undefined,
cliProgress: this._showCliProgress,
cliStyle: isCI ? "ci" : "fancy",
headers: this._headers ?? {},
tryHeaders: this._tryHeaders.slice(),
skipExisting: this._skipExisting
Expand Down Expand Up @@ -364,6 +366,7 @@ export class ModelDownloader {
this._downloader = await downloadSequence(
{
cliProgress: this._showCliProgress,
cliStyle: isCI ? "ci" : "fancy",
parallelDownloads: this._parallelDownloads
},
...partDownloads
Expand Down Expand Up @@ -541,6 +544,7 @@ export class CombinedModelDownloader {
this._downloader = await downloadSequence(
{
cliProgress: this._showCliProgress,
cliStyle: isCI ? "ci" : "fancy",
parallelDownloads: this._parallelDownloads
},
...(await Promise.all(this._downloaders)).flatMap((downloader) => downloader._specificFileDownloaders)
Expand Down
5 changes: 4 additions & 1 deletion test/utils/modelFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs from "fs-extra";
import chalk from "chalk";
import withStatusLogs from "../../src/utils/withStatusLogs.js";
import {withLockfile} from "../../src/utils/withLockfile.js";
import {isCI} from "../../src/config.js";

const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -44,7 +45,8 @@ export async function getModelFile(modelName: keyof typeof supportedModels) {
url: modelUrl,
directory: path.dirname(modelFilePath),
fileName: path.basename(modelFilePath),
cliProgress: true
cliProgress: true,
cliStyle: isCI ? "ci" : "fancy"
});
await downloader.download();

Expand Down Expand Up @@ -89,6 +91,7 @@ export async function downloadAllModels() {
console.info(`Downloading ${pendingDownloads.length} model${pendingDownloads.length === 1 ? "" : "s"}`);
const downloader = await downloadSequence({
cliProgress: true,
cliStyle: isCI ? "ci" : "fancy",
parallelDownloads: 4
}, ...pendingDownloads);
await downloader.download();
Expand Down

0 comments on commit 4b7ef5b

Please sign in to comment.