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.