Skip to content

Commit

Permalink
Fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xenova committed Dec 28, 2024
1 parent c99d08e commit 36ef7c7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/models/idefics3/image_processing_idefics3.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export class Idefics3ImageProcessor extends ImageProcessor {

const start_offset = i * pixel_attention_mask_stride + num_patches * h * w;
const end_offset = (i + 1) * pixel_attention_mask_stride;

// @ts-expect-error
pixel_attention_mask_data.fill(false, start_offset, end_offset);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/models/seamless_m4t/feature_extraction_seamless_m4t.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export class SeamlessM4TFeatureExtractor extends FeatureExtractor {
'int64',
new BigInt64Array(numPaddedFrames),
[1, numPaddedFrames],
)
padded_attention_mask.data.fill(1n, 0, num_frames);
);
/** @type {BigInt64Array} */ (padded_attention_mask.data).fill(1n, 0, num_frames);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ export class AutomaticSpeechRecognitionPipeline extends (/** @type {new (options
const max_new_tokens = Math.floor(aud.length / sampling_rate) * 6;
const outputs = await this.model.generate({ max_new_tokens, ...kwargs, ...inputs });

const text = this.processor.batch_decode(outputs, { skip_special_tokens: true })[0];
const text = this.processor.batch_decode(/** @type {Tensor} */(outputs), { skip_special_tokens: true })[0];
toReturn.push({ text });
}
return single ? toReturn[0] : toReturn;
Expand Down
7 changes: 3 additions & 4 deletions src/tokenizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,18 @@ class Unigram extends TokenizerModel {
* Create a new Unigram tokenizer model.
* @param {Object} config The configuration object for the Unigram model.
* @param {number} config.unk_id The ID of the unknown token
* @param {any[][]} config.vocab A 2D array representing a mapping of tokens to scores.
* @param {[string, number][]} config.vocab A 2D array representing a mapping of tokens to scores.
* @param {Object} moreConfig Additional configuration object for the Unigram model.
*/
constructor(config, moreConfig) {
super(config);

const vocabSize = config.vocab.length;
this.vocab = new Array(vocabSize);
/** @type {number[]} */
this.scores = new Array(vocabSize);
for (let i = 0; i < vocabSize; ++i) {
const piece = config.vocab[i];
this.vocab[i] = piece[0];
this.scores[i] = piece[1];
[this.vocab[i], this.scores[i]] = config.vocab[i];
}

this.unk_token_id = config.unk_id;
Expand Down

0 comments on commit 36ef7c7

Please sign in to comment.