Skip to content

Commit 67ff765

Browse files
committed
Formatting
1 parent 7b8a6f7 commit 67ff765

File tree

5 files changed

+47
-34
lines changed

5 files changed

+47
-34
lines changed

src/configs.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ export function getCacheShapes(config, options) {
291291
}
292292
}
293293
return cache_values;
294-
295294
} else if (config.model_type === 'granitemoehybrid') {
296295
const pkv_prefix = options?.prefix ?? 'past_key_values';
297296
const conv_prefix = pkv_prefix === 'present' ? 'present' : 'past';
@@ -300,10 +299,21 @@ export function getCacheShapes(config, options) {
300299
const cache_values = {};
301300

302301
// @ts-expect-error TS2339
303-
const { layer_types, num_attention_heads, num_key_value_heads, hidden_size, mamba_d_conv, mamba_n_heads, mamba_d_head, mamba_d_state, mamba_n_groups, mamba_expand } = config;
302+
const {
303+
layer_types,
304+
num_attention_heads,
305+
num_key_value_heads,
306+
hidden_size,
307+
mamba_d_conv,
308+
mamba_n_heads,
309+
mamba_d_head,
310+
mamba_d_state,
311+
mamba_n_groups,
312+
mamba_expand,
313+
} = config;
304314
const head_dim = hidden_size / num_attention_heads;
305315
const batch_size = options?.batch_size ?? 1;
306-
const conv_d_inner = (mamba_expand * hidden_size) + (2 * mamba_n_groups * mamba_d_state)
316+
const conv_d_inner = mamba_expand * hidden_size + 2 * mamba_n_groups * mamba_d_state;
307317
for (let i = 0; i < layer_types.length; ++i) {
308318
if (layer_types[i] === 'attention') {
309319
for (const kv of ['key', 'value']) {

src/generation/parameters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
* @typedef {GenerationFunctionParametersBase & Partial<import('./configuration_utils.js').GenerationConfig> & Record<string, any>} GenerationFunctionParameters
3737
*/
3838

39-
export { }; // Ensure this file is treated as a module
39+
export {}; // Ensure this file is treated as a module

src/models.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,13 +1398,18 @@ export class PreTrainedModel extends Callable {
13981398
]);
13991399
} else if (modelType === MODEL_TYPES.Supertonic) {
14001400
info = await Promise.all([
1401-
constructSessions(pretrained_model_name_or_path, {
1402-
text_encoder: 'text_encoder',
1403-
latent_denoiser: 'latent_denoiser',
1404-
voice_decoder: 'voice_decoder',
1405-
}, options),
1401+
constructSessions(
1402+
pretrained_model_name_or_path,
1403+
{
1404+
text_encoder: 'text_encoder',
1405+
latent_denoiser: 'latent_denoiser',
1406+
voice_decoder: 'voice_decoder',
1407+
},
1408+
options,
1409+
),
14061410
]);
1407-
} else { // should be MODEL_TYPES.EncoderOnly
1411+
} else {
1412+
// should be MODEL_TYPES.EncoderOnly
14081413
if (modelType !== MODEL_TYPES.EncoderOnly) {
14091414
const type = modelName ?? config?.model_type;
14101415
if (type !== 'custom') {
@@ -6141,8 +6146,8 @@ export class SamModel extends SamPreTrainedModel {
61416146
// Compute the image embeddings if they are missing
61426147
model_inputs = {
61436148
...model_inputs,
6144-
...(await this.get_image_embeddings(model_inputs))
6145-
}
6149+
...(await this.get_image_embeddings(model_inputs)),
6150+
};
61466151
} else {
61476152
model_inputs = { ...model_inputs };
61486153
}
@@ -6213,9 +6218,8 @@ export class Sam2ImageSegmentationOutput extends ModelOutput {
62136218
}
62146219
}
62156220

6216-
export class Sam2PreTrainedModel extends PreTrainedModel { }
6221+
export class Sam2PreTrainedModel extends PreTrainedModel {}
62176222
export class Sam2Model extends Sam2PreTrainedModel {
6218-
62196223
/**
62206224
* Compute image embeddings and positional image embeddings, given the pixel values of an image.
62216225
* @param {Object} model_inputs Object containing the model inputs.
@@ -6225,7 +6229,7 @@ export class Sam2Model extends Sam2PreTrainedModel {
62256229
async get_image_embeddings({ pixel_values }) {
62266230
// in:
62276231
// - pixel_values: tensor.float32[batch_size,3,1024,1024]
6228-
//
6232+
//
62296233
// out:
62306234
// - image_embeddings.0: tensor.float32[batch_size,32,256,256]
62316235
// - image_embeddings.1: tensor.float32[batch_size,64,128,128]
@@ -6238,29 +6242,30 @@ export class Sam2Model extends Sam2PreTrainedModel {
62386242
const { num_feature_levels } = this.config.vision_config;
62396243
const image_embeddings_name = Array.from({ length: num_feature_levels }, (_, i) => `image_embeddings.${i}`);
62406244

6241-
if (image_embeddings_name.some(name => !model_inputs[name])) {
6245+
if (image_embeddings_name.some((name) => !model_inputs[name])) {
62426246
// Compute the image embeddings if they are missing
62436247
model_inputs = {
62446248
...model_inputs,
6245-
...(await this.get_image_embeddings(model_inputs))
6246-
}
6249+
...(await this.get_image_embeddings(model_inputs)),
6250+
};
62476251
} else {
62486252
model_inputs = { ...model_inputs };
62496253
}
62506254

62516255
if (model_inputs.input_points) {
62526256
if (model_inputs.input_boxes && model_inputs.input_boxes.dims[1] !== 1) {
6253-
throw new Error('When both `input_points` and `input_boxes` are provided, the number of boxes per image must be 1.');
6257+
throw new Error(
6258+
'When both `input_points` and `input_boxes` are provided, the number of boxes per image must be 1.',
6259+
);
62546260
}
62556261
const shape = model_inputs.input_points.dims;
62566262
model_inputs.input_labels ??= ones(shape.slice(0, -1));
62576263
model_inputs.input_boxes ??= full([shape[0], 0, 4], 0.0);
6258-
6259-
} else if (model_inputs.input_boxes) { // only boxes
6264+
} else if (model_inputs.input_boxes) {
6265+
// only boxes
62606266
const shape = model_inputs.input_boxes.dims;
62616267
model_inputs.input_labels = full([shape[0], shape[1], 0], -1n);
62626268
model_inputs.input_points = full([shape[0], 1, 0, 2], 0.0);
6263-
62646269
} else {
62656270
throw new Error('At least one of `input_points` or `input_boxes` must be provided.');
62666271
}
@@ -6284,11 +6289,10 @@ export class Sam2Model extends Sam2PreTrainedModel {
62846289
return new Sam2ImageSegmentationOutput(await super._call(model_inputs));
62856290
}
62866291
}
6287-
export class EdgeTamModel extends Sam2Model { } // NOTE: extends Sam2Model
6288-
export class Sam3TrackerModel extends Sam2Model { } // NOTE: extends Sam2Model
6292+
export class EdgeTamModel extends Sam2Model {} // NOTE: extends Sam2Model
6293+
export class Sam3TrackerModel extends Sam2Model {} // NOTE: extends Sam2Model
62896294
//////////////////////////////////////////////////
62906295

6291-
62926296
//////////////////////////////////////////////////
62936297
// MarianMT models
62946298
export class MarianPreTrainedModel extends PreTrainedModel {}
@@ -6985,9 +6989,8 @@ export class SpeechT5HifiGan extends PreTrainedModel {
69856989
}
69866990
//////////////////////////////////////////////////
69876991

6988-
export class SupertonicPreTrainedModel extends PreTrainedModel { }
6992+
export class SupertonicPreTrainedModel extends PreTrainedModel {}
69896993
export class SupertonicForConditionalGeneration extends SupertonicPreTrainedModel {
6990-
69916994
async generate_speech({
69926995
// Required inputs
69936996
input_ids,
@@ -7003,7 +7006,9 @@ export class SupertonicForConditionalGeneration extends SupertonicPreTrainedMode
70037006

70047007
// 1. Text Encoder
70057008
const { last_hidden_state, durations } = await sessionRun(this.sessions['text_encoder'], {
7006-
input_ids, attention_mask, style,
7009+
input_ids,
7010+
attention_mask,
7011+
style,
70077012
});
70087013
durations.div_(speed); // Apply speed factor to duration
70097014

@@ -7036,11 +7041,10 @@ export class SupertonicForConditionalGeneration extends SupertonicPreTrainedMode
70367041
return {
70377042
waveform,
70387043
durations,
7039-
}
7044+
};
70407045
}
70417046
}
70427047

7043-
70447048
//////////////////////////////////////////////////
70457049
// TrOCR models
70467050
export class TrOCRPreTrainedModel extends PreTrainedModel {}

src/tokenizers.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,6 @@ class MetaspacePreTokenizer extends PreTokenizer {
22672267
// We add a prefix space if:
22682268
// (1) The normalized token does not already start with the replacement character.
22692269
!normalized.startsWith(this.replacement) &&
2270-
22712270
// and (2) either:
22722271
// (a) prepend_scheme is 'always'
22732272
// (b) prepend_scheme is 'first' and this is the first section
@@ -3379,7 +3378,7 @@ export class LlamaTokenizer extends PreTrainedTokenizer {
33793378
this.normalizer = null;
33803379
this.pre_tokenizer = new MetaspacePreTokenizer({
33813380
replacement: SPIECE_UNDERLINE,
3382-
prepend_scheme: "first",
3381+
prepend_scheme: 'first',
33833382
});
33843383
}
33853384
}

src/utils/tensor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,10 +1531,10 @@ export function randn(size) {
15311531
}
15321532

15331533
return new Tensor(
1534-
"float32",
1534+
'float32',
15351535
Float32Array.from({ length }, () => boxMullerRandom()),
15361536
size,
1537-
)
1537+
);
15381538
}
15391539

15401540
/**

0 commit comments

Comments
 (0)