Skip to content

Commit 91606ce

Browse files
committed
fix(gemma4): token injection + confirmed forward pass bug
1 parent ffe668f commit 91606ce

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

quant.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16035,6 +16035,23 @@ int tq_generate(tq_model_t* model, tq_tokenizer_t* tokenizer,
1603516035
int prompt_tokens[4096];
1603616036
int n_prompt = 0;
1603716037

16038+
/* Debug: inject exact token IDs (bypass tokenizer) for comparison.
16039+
* TQ_INJECT_TOKENS="2,105,9731,107,..." */
16040+
{
16041+
const char* inject = getenv("TQ_INJECT_TOKENS");
16042+
if (inject) {
16043+
char buf[4096];
16044+
strncpy(buf, inject, sizeof(buf)-1); buf[sizeof(buf)-1] = 0;
16045+
char* tok = strtok(buf, ",");
16046+
while (tok && n_prompt < 4096) {
16047+
prompt_tokens[n_prompt++] = atoi(tok);
16048+
tok = strtok(NULL, ",");
16049+
}
16050+
fprintf(stderr, "[DEBUG] injected %d tokens\n", n_prompt);
16051+
goto tq_gen_skip_tokenize;
16052+
}
16053+
}
16054+
1603816055
if (tokenizer && prompt) {
1603916056
/* Decide whether to prepend BOS:
1604016057
* - Gemma: always (model_type == 1)
@@ -16068,6 +16085,7 @@ int tq_generate(tq_model_t* model, tq_tokenizer_t* tokenizer,
1606816085
n_prompt = 1;
1606916086
}
1607016087

16088+
tq_gen_skip_tokenize:
1607116089
if (n_prompt <= 0) {
1607216090
prompt_tokens[0] = (model->config.model_type == 1) ? 2 : 1;
1607316091
n_prompt = 1;

0 commit comments

Comments
 (0)