Skip to content

Possible (very serious) bug in chat templates that use '<s>' token having a space added after it #7390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jukofyork opened this issue May 19, 2024 · 2 comments

Comments

@jukofyork
Copy link
Collaborator

You can see this in my PR where I tried to add the 'alpca' chat template:

#7383

Later in the PR chat I actully copied and pasted the:

    } else if (tmpl == "deepseek" || (tmpl.find("### Instruction:") != std::string::npos && tmpl.find("<|EOT|>") != std::string::npos)) {
        // deepseek-ai/deepseek-coder-33b-instruct
        for (auto message : chat) {
            std::string role(message->role);
            if (role == "system") {
                ss << message->content;
            } else if (role == "user") {
                ss << "### Instruction:\n" << message->content << "\n";
            } else if (role == "assistant") {
                ss << "### Response:\n" << message->content << "\n<|EOT|>\n";
            }
        }
        if (add_ass) {
            ss << "### Response:\n";
        }
    }

to:

    } else if (tmpl == "alpaca" || (tmpl.find("### Instruction:") != std::string::npos && tmpl.find("<|EOT|>") == std::string::npos)) {
        // deepseek-ai/deepseek-coder-33b-instruct
        for (auto message : chat) {
            std::string role(message->role);
            if (role == "system") {
                ss << message->content << "\n\n";
            } else if (role == "user") {
                ss << "### Instruction:\n" << message->content << "\n\n";
            } else if (role == "assistant") {
                ss << "### Response:\n" << message->content << "</s>\n\n";
            }
        }
        if (add_ass) {
            ss << "### Response:\n";
        }
    }

and the space between <s> and ### Instruction: persisted.

The effect of that space being added is very serious; my attempt at using phind-codellama using the deepseek chat template (with completely the wrong newlines and EOS token) actually worked much better.

@jukofyork
Copy link
Collaborator Author

I'm not even sure if it is the space that is causing it now, as this is the tokenization when using the deepseek chat template:

{"tid":"140097807843328","timestamp":1716135105,"level":"VERB","function":"update_slots","line":1955,"msg":"prompt tokenized","id_slot":0,"id_task":0,"n_ctx":16384,"n_keep":0,"n_prompt_tokens":43,"prompt_tokens":"<s> ### Instruction:\nCan you write me a C++ program to calculate logistic regression using GSL? Write a short driver in main to test it with hard coded values\n### Response:\n"}

that produces "sane" output from phind-codellama.

@jukofyork
Copy link
Collaborator Author

It was actually the extra </s>' that caused phind-codellama` to go wrong, so closing this/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant