try OpenELM 1.1B

This commit is contained in:
Adam Wilson
2025-08-19 17:06:12 -06:00
parent 52e72cce43
commit 7122235b4f
24 changed files with 54 additions and 78 deletions
@@ -6,9 +6,9 @@ from src.text_generation.common.model_id import ModelId
class AppleOpenELMFoundationModel(BaseFoundationModel):
"""apple/OpenELM-3B-Instruct implementation"""
"""apple/OpenELM-1_1B-Instruct implementation"""
MODEL_ID = ModelId.APPLE_OPENELM_3B_INSTRUCT
MODEL_ID = ModelId.APPLE_OPENELM_1_1B_INSTRUCT
def __init__(self, config: AppleOpenELMConfig = AppleOpenELMConfig()):
self.config = config
@@ -22,7 +22,7 @@ class FoundationModelFactory:
config = BaseModelConfig()
model_map = {
ModelId.APPLE_OPENELM_3B_INSTRUCT.value: AppleOpenELMFoundationModel,
ModelId.APPLE_OPENELM_1_1B_INSTRUCT.value: AppleOpenELMFoundationModel,
ModelId.META_LLAMA_3_2_3B_INSTRUCT.value: MetaLlamaFoundationModel,
ModelId.MICROSOFT_PHI_3_MINI4K_INSTRUCT.value: MicrosoftPhi3FoundationModel
}
@@ -37,7 +37,7 @@ class FoundationModelFactory:
"""Factory function to create the appropriate pipeline based on model name"""
pipeline_classes = {
ModelId.APPLE_OPENELM_3B_INSTRUCT.value: AppleOpenELMPipeline,
ModelId.APPLE_OPENELM_1_1B_INSTRUCT.value: AppleOpenELMPipeline,
ModelId.META_LLAMA_3_2_3B_INSTRUCT.value: MetaLlamaPipeline,
ModelId.MICROSOFT_PHI_3_MINI4K_INSTRUCT.value: MicrosoftPhi3MiniPipeline
}
@@ -17,7 +17,7 @@ class FoundationModelFactory:
config = BaseModelConfig()
model_map = {
ModelId.APPLE_OPENELM_3B_INSTRUCT.value: AppleOpenELMFoundationModel,
ModelId.APPLE_OPENELM_1_1B_INSTRUCT.value: AppleOpenELMFoundationModel,
ModelId.META_LLAMA_3_2_3B_INSTRUCT.value: MetaLlamaFoundationModel,
ModelId.MICROSOFT_PHI_3_MINI4K_INSTRUCT.value: MicrosoftPhi3FoundationModel
}
+5 -5
View File
@@ -24,11 +24,11 @@ class Constants:
PHI_3_MINI_4K_INSTRUCT__03_FEW_SHOT_EXAMPLES = "phi-3-mini-4k-instruct.03-few-shot"
PHI_3_MINI_4K_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT = "phi-3-mini-4k-instruct.04-few-shot-rag-plus-cot"
# OpenELM templates: apple/OpenELM-3B-Instruct
OPENELM_3B_INSTRUCT__01_BASIC = "openelm-3b-instruct.01-basic"
OPENELM_3B_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT = "openelm-3b-instruct.02-zero-shot-cot"
OPENELM_3B_INSTRUCT__03_FEW_SHOT_EXAMPLES = "openelm-3b-instruct.03-few-shot"
OPENELM_3B_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT = "openelm-3b-instruct.04-few-shot-rag-plus-cot"
# OpenELM templates: apple/OpenELM-1_1B-Instruct
OPENELM_1_1B_INSTRUCT__01_BASIC = "openelm-1-1b-instruct.01-basic"
OPENELM_1_1B_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT = "openelm-1-1b-instruct.02-zero-shot-cot"
OPENELM_1_1B_INSTRUCT__03_FEW_SHOT_EXAMPLES = "openelm-1-1b-instruct.03-few-shot"
OPENELM_1_1B_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT = "openelm-1-1b-instruct.04-few-shot-rag-plus-cot"
# meta-llama/Llama-3.2-3B-Instruct templates
LLAMA_1_1B_CHAT__01_BASIC = "llama-3.2-3b-instruct.01-basic"
+1 -1
View File
@@ -2,6 +2,6 @@ from enum import Enum
class ModelId(Enum):
APPLE_OPENELM_3B_INSTRUCT = "apple/OpenELM-3B-Instruct"
APPLE_OPENELM_1_1B_INSTRUCT = "apple/OpenELM-1_1B-Instruct"
META_LLAMA_3_2_3B_INSTRUCT = "meta-llama/Llama-3.2-3B-Instruct"
MICROSOFT_PHI_3_MINI4K_INSTRUCT = "microsoft/Phi-3-mini-4k-instruct"
@@ -38,16 +38,8 @@ class ChainOfThoughtSecurityGuidelinesService(BaseSecurityGuidelinesService):
Dict[str, str]: Mapping from model name/identifier to CoT template ID
"""
return {
# Phi-3 models
"phi-3-mini-4k-instruct": self.constants.PromptTemplateIds.PHI_3_MINI_4K_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
"microsoft/Phi-3-mini-4K-Instruct": self.constants.PromptTemplateIds.PHI_3_MINI_4K_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
# OpenELM models
"openelm-3b-instruct": self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
"apple/OpenELM-3B-Instruct": self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
# Llama models
"llama-3.2-3b-instruct": self.constants.PromptTemplateIds.LLAMA_1_1B_CHAT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
"microsoft/Phi-3-mini-4K-Instruct": self.constants.PromptTemplateIds.PHI_3_MINI_4K_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
"apple/OpenELM-1_1B-Instruct": self.constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
"meta-llama/Llama-3.2-3B-Instruct": self.constants.PromptTemplateIds.LLAMA_1_1B_CHAT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
}
@@ -38,17 +38,9 @@ class RagContextSecurityGuidelinesService(BaseSecurityGuidelinesService):
Dict[str, str]: Mapping from model name/identifier to few-shot template ID
"""
return {
# Phi-3 models
"phi-3-mini-4k-instruct": self.constants.PromptTemplateIds.PHI_3_MINI_4K_INSTRUCT__03_FEW_SHOT_EXAMPLES,
"microsoft/phi-3-mini-4k-instruct": self.constants.PromptTemplateIds.PHI_3_MINI_4K_INSTRUCT__03_FEW_SHOT_EXAMPLES,
# OpenELM models
"openelm-3b-instruct": self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__03_FEW_SHOT_EXAMPLES,
"apple/openelm-3b-instruct": self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__03_FEW_SHOT_EXAMPLES,
# Llama models
"llama-3.2-3b-instruct": self.constants.PromptTemplateIds.LLAMA_1_1B_CHAT__03_FEW_SHOT_EXAMPLES,
"meta-llama/llama-3.2-3b-instruct": self.constants.PromptTemplateIds.LLAMA_1_1B_CHAT__03_FEW_SHOT_EXAMPLES,
"apple/OpenELM-1_1B-Instruct": self.constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__03_FEW_SHOT_EXAMPLES,
"meta-llama/llama-3.2-3b-instruct": self.constants.PromptTemplateIds.LLAMA_1_1B_CHAT__03_FEW_SHOT_EXAMPLES
}
def _get_template(self, user_prompt: str, template_id: str) -> StringPromptTemplate:
@@ -41,17 +41,9 @@ class RagPlusCotSecurityGuidelinesService(BaseSecurityGuidelinesService):
Dict[str, str]: Mapping from model name/identifier to RAG+CoT template ID
"""
return {
# Phi-3 models
"phi-3-mini-4k-instruct": self.constants.PromptTemplateIds.PHI_3_MINI_4K_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT,
"microsoft/phi-3-mini-4k-instruct": self.constants.PromptTemplateIds.PHI_3_MINI_4K_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT,
# OpenELM models
"openelm-3b-instruct": self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT,
"apple/openelm-3b-instruct": self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT,
# Llama models
"llama-3.2-3b-instruct": self.constants.PromptTemplateIds.LLAMA_1_1B_CHAT__04_FEW_SHOT_RAG_PLUS_COT,
"meta-llama/llama-3.2-3b-instruct": self.constants.PromptTemplateIds.LLAMA_1_1B_CHAT__04_FEW_SHOT_RAG_PLUS_COT,
"apple/OpenELM-1_1B-Instruct": self.constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT,
"meta-llama/llama-3.2-3b-instruct": self.constants.PromptTemplateIds.LLAMA_1_1B_CHAT__04_FEW_SHOT_RAG_PLUS_COT
}
def _get_template(self, user_prompt: str, template_id: str) -> StringPromptTemplate:
@@ -106,11 +106,11 @@ class TextGenerationCompletionService(AbstractTextGenerationCompletionService):
},
# OpenELM models
"apple/openelm-3b-instruct": {
PromptTemplateType.BASIC.value: self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__01_BASIC,
PromptTemplateType.ZERO_SHOT_COT.value: self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
PromptTemplateType.FEW_SHOT.value: self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__03_FEW_SHOT_EXAMPLES,
PromptTemplateType.RAG_PLUS_COT.value: self.constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT,
"apple/OpenELM-1_1B-Instruct": {
PromptTemplateType.BASIC.value: self.constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__01_BASIC,
PromptTemplateType.ZERO_SHOT_COT.value: self.constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT,
PromptTemplateType.FEW_SHOT.value: self.constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__03_FEW_SHOT_EXAMPLES,
PromptTemplateType.RAG_PLUS_COT.value: self.constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT,
},
# Llama models