Skip to content

Commit d3205de

Browse files
committed
Move image tokens out of call function
1 parent cadf689 commit d3205de

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/models/idefics3/processing_idefics3.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export class Idefics3Processor extends Processor {
6464
static tokenizer_class = AutoTokenizer
6565
static uses_processor_config = true;
6666

67+
fake_image_token = "<fake_token_around_image>";
68+
image_token = "<image>";
69+
global_img_token = "<global-img>";
70+
6771
/**
6872
*
6973
* @param {string|string[]} text
@@ -87,34 +91,29 @@ export class Idefics3Processor extends Processor {
8791
const image_rows = image_inputs.rows ?? [new Array(text.length).fill(0)];
8892
const image_cols = image_inputs.cols ?? [new Array(text.length).fill(0)];
8993

90-
// TODO: Move to constructor
9194
const image_seq_len = this.config.image_seq_len;
92-
const fake_image_token = "<fake_token_around_image>";
93-
const image_token = "<image>";
94-
const global_img_token = "<global-img>";
95-
9695
const n_images_in_text = []
9796
const prompt_strings = [];
9897
for (let i = 0; i < text.length; ++i) {
9998
const sample = text[i];
10099
const sample_rows = image_rows[i];
101100
const sample_cols = image_cols[i];
102101

103-
n_images_in_text.push(count(sample, image_token));
102+
n_images_in_text.push(count(sample, this.image_token));
104103

105104
// Replace the image token with fake tokens around the expanded image token sequence of length `image_seq_len`
106105
const image_prompt_strings = sample_rows.map(
107106
(n_rows, j) => get_image_prompt_string(
108107
n_rows,
109108
sample_cols[j],
110109
image_seq_len,
111-
fake_image_token,
112-
image_token,
113-
global_img_token
110+
this.fake_image_token,
111+
this.image_token,
112+
this.global_img_token,
114113
)
115114
);
116115

117-
const split_sample = sample.split(image_token);
116+
const split_sample = sample.split(this.image_token);
118117
if (split_sample.length === 0) {
119118
throw new Error("The image token should be present in the text.");
120119
}

0 commit comments

Comments
 (0)