Skip to content

Commit 1538e3a

Browse files
nico-martinxenova
andauthored
Override generation config with do_sample=false if temperature=0 is set (#1431)
* #1429 set generation_config.do_sample = false if temperature=0 * removed .idea folder * removed package-lock * Update src/models.js Co-authored-by: Joshua Lochner <[email protected]> --------- Co-authored-by: Joshua Lochner <[email protected]>
1 parent c670bb9 commit 1538e3a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_modules
44
.cache
55
.DS_STORE
66
deno.lock
7+
.idea
78

89
# Do not track build artifacts/generated files
910
/dist

src/models.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,12 @@ export class PreTrainedModel extends Callable {
14271427
processors.push(new ClassifierFreeGuidanceLogitsProcessor(generation_config.guidance_scale));
14281428
}
14291429

1430+
1431+
if (generation_config.temperature === 0 && generation_config.do_sample) {
1432+
console.warn('`do_sample` changed to false because `temperature: 0` implies greedy sampling (always selecting the most likely token), which is incompatible with `do_sample: true`.');
1433+
generation_config.do_sample = false;
1434+
}
1435+
14301436
if (generation_config.do_sample) {
14311437
if (generation_config.temperature !== null && generation_config.temperature !== 1.0) {
14321438
processors.push(new TemperatureLogitsWarper(generation_config.temperature));

0 commit comments

Comments
 (0)