Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion llama/addon/AddonContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class AddonContextSampleTokenWorker : public Napi::AsyncWorker {
llama_token_data_array cur_p;
sampler->sample(ctx->ctx, batchLogitIndex, cur_p, returnProbabilities || returnConfidence);

if (!(cur_p.selected >= 0 && cur_p.selected < (int32_t)cur_p.size)) {
if (cur_p.size == 0 || !(cur_p.selected >= 0 && cur_p.selected < (int32_t)cur_p.size)) {
no_output = true;
return;
}
Expand Down
10 changes: 7 additions & 3 deletions llama/addon/AddonSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ void AddonSampler::acceptToken(llama_token token) {
void AddonSampler::sample(struct llama_context* llamaContext, int32_t batchLogitIndex, llama_token_data_array& curP, bool forceGrammar) {
setTokenCandidates(llamaContext, batchLogitIndex, curP);

if (curP.size == 0) {
return;
}

if (forceGrammar && grammarEvaluationState != nullptr && grammarEvaluationState->sampler != nullptr) {
llama_sampler_apply(grammarEvaluationState->sampler, &curP);
llama_sampler_apply(chain, &curP);
Expand Down Expand Up @@ -287,7 +291,7 @@ Napi::Value AddonSampler::ApplyConfig(const Napi::CallbackInfo& info) {
temperatureSampler = nullptr;
}

if (temperatureSampler_temperature <= 0) {
if (temperatureSampler_temperature <= 0.0f) {
greedySampler = llama_sampler_init_greedy();
} else {
temperatureSampler = llama_sampler_init_temp(temperatureSampler_temperature);
Expand Down Expand Up @@ -321,7 +325,7 @@ Napi::Value AddonSampler::ApplyConfig(const Napi::CallbackInfo& info) {
minPSampler = nullptr;
}

if (minPSampler_minP != 0) {
if (minPSampler_minP > 0.0f) {
minPSampler = llama_sampler_init_min_p(minPSampler_minP, min_keep);
}
}
Expand Down Expand Up @@ -366,7 +370,7 @@ Napi::Value AddonSampler::ApplyConfig(const Napi::CallbackInfo& info) {
topPSampler = nullptr;
}

if (topPSampler_topP >= 1) {
if (topPSampler_topP >= 0.0f && topPSampler_topP <= 1.0f) {
topPSampler = llama_sampler_init_top_p(topPSampler_topP, min_keep);
}
}
Expand Down
2 changes: 1 addition & 1 deletion llama/addon/AddonSampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AddonSampler : public Napi::ObjectWrap<AddonSampler> {
int topKSampler_topK = 0;

llama_sampler * topPSampler = nullptr;
float topPSampler_topP = 0.0f; // Top p sampling >=1.0 = disabled
float topPSampler_topP = 1.0f; // Top p sampling >=1.0 = disabled

llama_sampler * xtcSampler = nullptr;
float xtcSampler_probability = 0;
Expand Down
113 changes: 75 additions & 38 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"@nolebase/vitepress-plugin-og-image": "^2.18.2",
"@resvg/resvg-js": "^2.6.2",
"@semantic-release/exec": "^7.1.0",
"@semantic-release/github": "^12.0.6",
"@semantic-release/github": "^12.0.9",
"@semantic-release/npm": "^13.1.5",
"@shikijs/vitepress-twoslash": "^3.22.0",
"@stylistic/eslint-plugin": "^5.8.0",
Expand All @@ -170,7 +170,7 @@
"husky": "^9.1.7",
"rehype": "^13.0.2",
"rimraf": "^6.1.3",
"semantic-release": "^25.0.3",
"semantic-release": "^25.0.8",
"sharp": "^0.34.5",
"tslib": "^2.8.1",
"typedoc": "^0.28.17",
Expand All @@ -186,7 +186,7 @@
"zx": "^8.8.5"
},
"dependencies": {
"@huggingface/jinja": "^0.5.6",
"@huggingface/jinja": "^0.5.9",
"async-retry": "^1.3.3",
"bytes": "^3.1.2",
"chalk": "^5.6.2",
Expand All @@ -202,12 +202,12 @@
"lifecycle-utils": "^4.0.1",
"log-symbols": "^7.0.1",
"nanoid": "^5.1.6",
"node-addon-api": "^8.6.0",
"node-addon-api": "^8.9.1",
"ora": "^9.3.0",
"pretty-ms": "^9.3.0",
"proper-lockfile": "^4.1.2",
"semver": "^7.7.1",
"simple-git": "^3.33.0",
"simple-git": "^3.36.0",
"slice-ansi": "^8.0.0",
"stdout-update": "^4.0.1",
"strip-ansi": "^7.2.0",
Expand Down
Loading
Loading