From aaeddcdbda547775ab6c8a9ac2f1c6325d7bbf31 Mon Sep 17 00:00:00 2001 From: DrStranded Date: Thu, 3 Sep 2026 16:00:10 -0400 Subject: [PATCH] Add GraniteInstruct prompt style and Granite 3.3 instruct models Granite 3.x instruct models have their own chat template; without a style they can only be run as GenericBase (bare completion prompt), which measures the missing template rather than the model (granite-3.3-2b-instruct: 4.1 -> 10.6 pass@1 on LCB v6 with the template). The branch mirrors the LLaMa3 one. --- lcb_runner/lm_styles.py | 16 ++++++++++++++++ lcb_runner/prompts/code_generation.py | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lcb_runner/lm_styles.py b/lcb_runner/lm_styles.py index d10b2117..405ccf32 100644 --- a/lcb_runner/lm_styles.py +++ b/lcb_runner/lm_styles.py @@ -31,6 +31,7 @@ class LMStyle(Enum): QwQ = "QwQ" LLaMa3 = "LLaMa3" DeepSeekR1 = "DeepSeekR1" + GraniteInstruct = "GraniteInstruct" TogetherAI = "TogetherAI" @@ -861,6 +862,21 @@ def to_dict(self) -> dict: datetime(2024, 4, 1), "https://huggingface.co/agentica-org/DeepCoder-14B-Preview", ), + ## Granite 3.3 Instruct (2B and 8B) + LanguageModel( + "ibm-granite/granite-3.3-2b-instruct", + "Granite-3.3-2B-Ins", + LMStyle.GraniteInstruct, + datetime(2025, 4, 16), + "https://huggingface.co/ibm-granite/granite-3.3-2b-instruct", + ), + LanguageModel( + "ibm-granite/granite-3.3-8b-instruct", + "Granite-3.3-8B-Ins", + LMStyle.GraniteInstruct, + datetime(2025, 4, 16), + "https://huggingface.co/ibm-granite/granite-3.3-8b-instruct", + ), ] LanguageModelStore: dict[str, LanguageModel] = { diff --git a/lcb_runner/prompts/code_generation.py b/lcb_runner/prompts/code_generation.py index 22ba3f82..37e96a5a 100644 --- a/lcb_runner/prompts/code_generation.py +++ b/lcb_runner/prompts/code_generation.py @@ -335,6 +335,31 @@ def format_prompt_generation( prompt += f"{get_deepseek_r1_question_template_answer(question)}" return prompt + if LanguageModelStyle == LMStyle.GraniteInstruct: + chat_messages = [ + { + "role": "system", + "content": PromptConstants.SYSTEM_MESSAGE_GENERIC, + }, + { + "role": "user", + "content": get_generic_question_template_answer(question), + }, + ] + from transformers import AutoTokenizer + + # Granite 3.x instruct models share one chat template; only the template is used here. + tokenizer = AutoTokenizer.from_pretrained( + "ibm-granite/granite-3.3-2b-instruct", padding_side="left" + ) + return tokenizer.apply_chat_template( + chat_messages, + tokenize=False, + add_generation_prompt=True, + truncation=False, + padding=False, + ) + if LanguageModelStyle == LMStyle.GenericBase: prompt = get_base_model_question_template_answer(question) return prompt