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
@@ -1,10 +1,10 @@
name: '#4 (1-20) | RAG + CoT | apple/OpenELM-3B-Instruct'
name: '#4 (1-20) | RAG + CoT | apple/OpenELM-1_1B-Instruct'
on:
workflow_dispatch:
jobs:
test-prompts-1-20:
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_3b_instruct.base.yml
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_1_1b_instruct.base.yml
with:
batch_offset: 0
range_name: "1-20"
@@ -1,10 +1,10 @@
name: '#4 (21-40) | RAG + CoT | apple/OpenELM-3B-Instruct'
name: '#4 (21-40) | RAG + CoT | apple/OpenELM-1_1B-Instruct'
on:
workflow_dispatch:
jobs:
test-prompts-21-40:
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_3b_instruct.base.yml
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_1_1b_instruct.base.yml
with:
batch_offset: 20
range_name: "21-40"
@@ -1,10 +1,10 @@
name: '#4 (41-60) | RAG + CoT | apple/OpenELM-3B-Instruct'
name: '#4 (41-60) | RAG + CoT | apple/OpenELM-1_1B-Instruct'
on:
workflow_dispatch:
jobs:
test-prompts-41-60:
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_3b_instruct.base.yml
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_1_1b_instruct.base.yml
with:
batch_offset: 40
range_name: "41-60"
@@ -1,10 +1,10 @@
name: '#4 (61-80) | RAG + CoT | apple/OpenELM-3B-Instruct'
name: '#4 (61-80) | RAG + CoT | apple/OpenELM-1_1B-Instruct'
on:
workflow_dispatch:
jobs:
test-prompts-61-80:
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_3b_instruct.base.yml
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_1_1b_instruct.base.yml
with:
batch_offset: 60
range_name: "61-80"
@@ -1,10 +1,10 @@
name: '#4 (81-100) | RAG + CoT | apple/OpenELM-3B-Instruct'
name: '#4 (81-100) | RAG + CoT | apple/OpenELM-1_1B-Instruct'
on:
workflow_dispatch:
jobs:
test-prompts-81-100:
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_3b_instruct.base.yml
uses: ./.github/workflows/test_04_malicious_prompts_rag_and_cot_apple_openelm_1_1b_instruct.base.yml
with:
batch_offset: 80
range_name: "81-100"
@@ -1,4 +1,4 @@
name: 'Reusable Test #4 | RAG + CoT | apple/OpenELM-3B-Instruct'
name: 'Reusable Test #4 | RAG + CoT | apple/OpenELM-1_1B-Instruct'
on:
workflow_call:
inputs:
@@ -23,5 +23,5 @@ jobs:
batch_offset: ${{ inputs.batch_offset }}
range_name: ${{ inputs.range_name }}
batch_size: ${{ inputs.batch_size }}
test_file_path: tests/integration/test_04_malicious_prompts_rag_and_cot_apple_openelm_3b_instruct.py
model_display_name: apple/OpenELM-3B-Instruct
test_file_path: tests/integration/test_04_malicious_prompts_rag_and_cot_apple_openelm_1_1b_instruct.py
model_display_name: apple/OpenELM-1_1B-Instruct
@@ -1,4 +1,4 @@
name: 'Test #4 | RAG + CoT | apple/OpenELM-3B-Instruct'
name: 'Test #4 | RAG + CoT | apple/OpenELM-1_1B-Instruct'
on:
workflow_dispatch:
@@ -21,7 +21,7 @@ jobs:
- name: 'run text generation tests'
shell: bash
run: pytest tests/integration/test_04_malicious_prompts_rag_and_cot_apple_openelm_3b_instruct.py -s --disable-warnings
run: pytest tests/integration/test_04_malicious_prompts_rag_and_cot_apple_openelm_1_1b_instruct.py -s --disable-warnings
- name: Check for changes
id: verify-changed-files
@@ -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
+1 -1
View File
@@ -2,7 +2,7 @@
# Array of model names
models=(
"apple/OpenELM-3B-Instruct"
"apple/OpenELM-1_1B-Instruct"
"meta-llama/Llama-3.2-3B-Instruct"
"microsoft/Phi-3-mini-4k-instruct"
)
@@ -12,7 +12,7 @@ from src.text_generation.services.nlp.abstract_text_generation_completion_servic
@pytest.mark.mitigation
@pytest.mark.parametrize("model_id", [
ModelId.MICROSOFT_PHI_3_MINI4K_INSTRUCT,
ModelId.APPLE_OPENELM_3B_INSTRUCT,
ModelId.APPLE_OPENELM_1_1B_INSTRUCT,
ModelId.META_LLAMA_3_2_3B_INSTRUCT
])
def test_04_malicious_prompts_rag_and_cot(
@@ -3,7 +3,7 @@ from src.text_generation.services.nlp.abstract_text_generation_completion_servic
from tests.integration.test_utils import get_prompt_batch, run_prompt_analysis_test
def test_00_benign_prompts_no_mitigation_apple_openelm_3b_instruct(
def test_00_benign_prompts_no_mitigation_apple_openelm_1_1b_instruct(
text_generation_completion_service: AbstractTextGenerationCompletionService,
semantic_similarity_service,
math_prompts,
@@ -19,7 +19,7 @@ def test_00_benign_prompts_no_mitigation_apple_openelm_3b_instruct(
results = run_prompt_analysis_test(
test_id=0,
model_id=ModelId.APPLE_OPENELM_3B_INSTRUCT,
model_id=ModelId.APPLE_OPENELM_1_1B_INSTRUCT,
text_generation_completion_service=text_generation_completion_service,
semantic_similarity_service=semantic_similarity_service,
prompts=prompt_batch,
@@ -7,7 +7,7 @@ import pytest
@pytest.mark.mitigation
def test_01_malicious_prompts_no_mitigation_apple_openelm_3b_instruct(
def test_01_malicious_prompts_no_mitigation_apple_openelm_1_1b_instruct(
text_generation_completion_service: AbstractTextGenerationCompletionService,
semantic_similarity_service,
malicious_prompts,
@@ -20,7 +20,7 @@ def test_01_malicious_prompts_no_mitigation_apple_openelm_3b_instruct(
results = run_prompt_analysis_test(
test_id=1,
model_id=ModelId.APPLE_OPENELM_3B_INSTRUCT,
model_id=ModelId.APPLE_OPENELM_1_1B_INSTRUCT,
text_generation_completion_service=text_generation_completion_service,
semantic_similarity_service=semantic_similarity_service,
prompts=prompt_batch,
@@ -7,7 +7,7 @@ import pytest
@pytest.mark.mitigation
def test_02_malicious_prompts_cot_apple_openelm_3b_instruct(
def test_02_malicious_prompts_cot_apple_openelm_1_1b_instruct(
text_generation_completion_service: AbstractTextGenerationCompletionService,
semantic_similarity_service,
malicious_prompts,
@@ -21,7 +21,7 @@ def test_02_malicious_prompts_cot_apple_openelm_3b_instruct(
results = run_prompt_analysis_test(
test_id=2,
model_id=ModelId.APPLE_OPENELM_3B_INSTRUCT,
model_id=ModelId.APPLE_OPENELM_1_1B_INSTRUCT,
text_generation_completion_service=text_generation_completion_service,
semantic_similarity_service=semantic_similarity_service,
prompts=prompt_batch,
@@ -7,7 +7,7 @@ import pytest
@pytest.mark.mitigation
def test_03_malicious_prompts_rag_apple_openelm_3b_instruct(
def test_03_malicious_prompts_rag_apple_openelm_1_1b_instruct(
text_generation_completion_service: AbstractTextGenerationCompletionService,
semantic_similarity_service,
malicious_prompts,
@@ -21,7 +21,7 @@ def test_03_malicious_prompts_rag_apple_openelm_3b_instruct(
results = run_prompt_analysis_test(
test_id=3,
model_id=ModelId.APPLE_OPENELM_3B_INSTRUCT,
model_id=ModelId.APPLE_OPENELM_1_1B_INSTRUCT,
text_generation_completion_service=text_generation_completion_service,
semantic_similarity_service=semantic_similarity_service,
prompts=prompt_batch,
@@ -7,7 +7,7 @@ import pytest
@pytest.mark.mitigation
def test_04_malicious_prompts_rag_and_cot_apple_openelm_3b_instruct(
def test_04_malicious_prompts_rag_and_cot_apple_openelm_1_1b_instruct(
text_generation_completion_service: AbstractTextGenerationCompletionService,
semantic_similarity_service,
malicious_prompts,
@@ -22,7 +22,7 @@ def test_04_malicious_prompts_rag_and_cot_apple_openelm_3b_instruct(
results = run_prompt_analysis_test(
test_id=4,
model_id=ModelId.APPLE_OPENELM_3B_INSTRUCT,
model_id=ModelId.APPLE_OPENELM_1_1B_INSTRUCT,
text_generation_completion_service=text_generation_completion_service,
semantic_similarity_service=semantic_similarity_service,
prompts=prompt_batch,
@@ -161,7 +161,7 @@ def test_4_save_rag_plus_cot_template_llama(constants, prompt_template_service):
"""
Model: apple/OpenELM-3B-Instruct
Model: apple/OpenELM-1_1B-Instruct
"""
@pytest.mark.repository
@@ -175,7 +175,7 @@ def test_1_save_basic_template_apple_openelm(constants, prompt_template_service)
### Response: """,
input_variables=[constants.INPUT_VARIABLE_TOKEN]
)
id = constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__01_BASIC
id = constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__01_BASIC
prompt_template_service.add(id, prompt_template)
@pytest.mark.repository
@@ -191,7 +191,7 @@ def test_2_save_zero_shot_cot_template_apple_openelm(constants, prompt_template_
### Response: """,
input_variables=[constants.INPUT_VARIABLE_TOKEN]
)
id = constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT
id = constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__02_ZERO_SHOT_CHAIN_OF_THOUGHT
prompt_template_service.add(id, prompt_template)
@pytest.mark.repository
@@ -209,7 +209,7 @@ def test_3_save_rag_few_shot_template_apple_openelm(constants, prompt_template_s
template=template_string
)
template_id = constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__03_FEW_SHOT_EXAMPLES
template_id = constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__03_FEW_SHOT_EXAMPLES
prompt_template_service.add(template_id, prompt_template)
@pytest.mark.repository
@@ -229,5 +229,5 @@ def test_4_save_rag_plus_cot_template_apple_openelm(constants, prompt_template_s
template=template_string
)
template_id = constants.PromptTemplateIds.OPENELM_3B_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT
template_id = constants.PromptTemplateIds.OPENELM_1_1B_INSTRUCT__04_FEW_SHOT_RAG_PLUS_COT
prompt_template_service.add(template_id, prompt_template)