Skip to content

get_loglikelihood function in hfmodel.py is not working for Gemma 3 models #157

@MTDickens

Description

@MTDickens

For Gemma 3 models, you must add <bos> token at the beginning of your input to make the model generate meaningful tokens. Yet inside the function are

        prompts_tokens = self.tokenizer(contents, return_tensors='pt',add_special_tokens=False, padding=True).to(self.device)
        prefix_tokens = self.tokenizer(prefix, return_tensors='pt',add_special_tokens=False, padding=True).input_ids[0].to(self.device)

whose add_special_tokens options are both false. This means the tokenizer can't automatically add the <bos> token, which I think is a minor bug here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions