1- const { Tensor } = require ( " ./tensor_utils.js" ) ;
2- const {
1+ import { Tensor } from ' ./tensor_utils.js' ;
2+ import {
33 Callable ,
44 exists ,
55 log_softmax
6- } = require ( " ./utils.js" ) ;
6+ } from ' ./utils.js' ;
77
88/**
99 * A class representing a list of logits processors. A logits processor is a function that modifies the logits
@@ -12,7 +12,7 @@ const {
1212 *
1313 * @extends Callable
1414 */
15- class LogitsProcessorList extends Callable {
15+ export class LogitsProcessorList extends Callable {
1616 /**
1717 * Constructs a new instance of `LogitsProcessorList`.
1818 */
@@ -66,7 +66,7 @@ class LogitsProcessorList extends Callable {
6666 * Base class for processing logits.
6767 * @extends Callable
6868 */
69- class LogitsProcessor extends Callable {
69+ export class LogitsProcessor extends Callable {
7070 /**
7171 * Apply the processor to the input logits.
7272 *
@@ -85,7 +85,7 @@ class LogitsProcessor extends Callable {
8585 *
8686 * @extends LogitsProcessor
8787 */
88- class ForceTokensLogitsProcessor extends LogitsProcessor {
88+ export class ForceTokensLogitsProcessor extends LogitsProcessor {
8989 /**
9090 * Constructs a new instance of `ForceTokensLogitsProcessor`.
9191 *
@@ -117,7 +117,7 @@ class ForceTokensLogitsProcessor extends LogitsProcessor {
117117 * A LogitsProcessor that forces a BOS token at the beginning of the generated sequence.
118118 * @extends LogitsProcessor
119119 */
120- class ForcedBOSTokenLogitsProcessor extends LogitsProcessor {
120+ export class ForcedBOSTokenLogitsProcessor extends LogitsProcessor {
121121 /**
122122 * Create a ForcedBOSTokenLogitsProcessor.
123123 * @param {number } bos_token_id - The ID of the beginning-of-sequence token to be forced.
@@ -146,7 +146,7 @@ class ForcedBOSTokenLogitsProcessor extends LogitsProcessor {
146146 *
147147 * @extends LogitsProcessor
148148 */
149- class ForcedEOSTokenLogitsProcessor extends LogitsProcessor {
149+ export class ForcedEOSTokenLogitsProcessor extends LogitsProcessor {
150150 /**
151151 * Create a ForcedEOSTokenLogitsProcessor.
152152 * @param {number } max_length - Max length of the sequence.
@@ -174,7 +174,7 @@ class ForcedEOSTokenLogitsProcessor extends LogitsProcessor {
174174 * A LogitsProcessor that handles adding timestamps to generated text.
175175 * @extends LogitsProcessor
176176 */
177- class WhisperTimeStampLogitsProcessor extends LogitsProcessor {
177+ export class WhisperTimeStampLogitsProcessor extends LogitsProcessor {
178178 /**
179179 * Constructs a new WhisperTimeStampLogitsProcessor.
180180 * @param {object } generate_config - The config object passed to the `generate()` method of a transformer model.
@@ -249,7 +249,7 @@ class WhisperTimeStampLogitsProcessor extends LogitsProcessor {
249249 *
250250 * @extends LogitsProcessor
251251 */
252- class NoRepeatNGramLogitsProcessor extends LogitsProcessor {
252+ export class NoRepeatNGramLogitsProcessor extends LogitsProcessor {
253253 /**
254254 * Create a NoRepeatNGramLogitsProcessor.
255255 * @param {number } no_repeat_ngram_size - The no-repeat-ngram size. All ngrams of this size can only occur once.
@@ -340,7 +340,7 @@ class NoRepeatNGramLogitsProcessor extends LogitsProcessor {
340340 *
341341 * @extends LogitsProcessor
342342 */
343- class RepetitionPenaltyLogitsProcessor extends LogitsProcessor {
343+ export class RepetitionPenaltyLogitsProcessor extends LogitsProcessor {
344344 /**
345345 * Create a RepetitionPenaltyLogitsProcessor.
346346 * @param {number } penalty - The penalty to apply for repeated tokens.
@@ -372,7 +372,7 @@ class RepetitionPenaltyLogitsProcessor extends LogitsProcessor {
372372}
373373
374374
375- class GenerationConfig {
375+ export class GenerationConfig {
376376 constructor ( kwargs = { } ) {
377377 // Parameters that control the length of the output
378378 // TODO: extend the configuration with correct types
@@ -465,15 +465,3 @@ class GenerationConfig {
465465 this . generation_kwargs = kwargs . generation_kwargs ?? { } ;
466466 }
467467}
468-
469- module . exports = {
470- LogitsProcessor,
471- LogitsProcessorList,
472- GenerationConfig,
473- ForcedBOSTokenLogitsProcessor,
474- ForcedEOSTokenLogitsProcessor,
475- WhisperTimeStampLogitsProcessor,
476- ForceTokensLogitsProcessor,
477- NoRepeatNGramLogitsProcessor,
478- RepetitionPenaltyLogitsProcessor
479- } ;
0 commit comments