mirror of
https://github.com/lightbroker/llmsecops-research.git
synced 2026-07-09 14:38:07 +02:00
new test for GH actions
This commit is contained in:
@@ -8,18 +8,19 @@ from src.text_generation.common.model_id import ModelId
|
||||
class AppleOpenELMFoundationModel(BaseFoundationModel):
|
||||
"""apple/OpenELM-3B-Instruct implementation"""
|
||||
|
||||
MODEL_ID = ModelId.APPLE_OPENELM_3B_INSTRUCT.value
|
||||
|
||||
def __init__(self, config: AppleOpenELMConfig = AppleOpenELMConfig()):
|
||||
self.config = config
|
||||
super().__init__()
|
||||
self.MODEL_ID = ModelId.APPLE_OPENELM_3B_INSTRUCT.value
|
||||
super().__init__(config)
|
||||
|
||||
def _load_model(self) -> None:
|
||||
self.tokenizer = AutoTokenizer.from_pretrained(
|
||||
self.MODEL_ID,
|
||||
self.MODEL_ID.value,
|
||||
local_files_only=self.config.local_files_only
|
||||
)
|
||||
self.model = AutoModelForCausalLM.from_pretrained(
|
||||
self.MODEL_ID,
|
||||
self.MODEL_ID.value,
|
||||
local_files_only=self.config.local_files_only
|
||||
)
|
||||
|
||||
|
||||
@@ -10,6 +10,4 @@ class BaseModelConfig:
|
||||
repetition_penalty: float = 1.1
|
||||
use_fast: bool = True
|
||||
local_files_only: bool = False
|
||||
|
||||
|
||||
|
||||
torch_dtype: str = "auto"
|
||||
|
||||
+5
-5
@@ -27,10 +27,10 @@ class FoundationModelFactory:
|
||||
ModelId.MICROSOFT_PHI_3_MINI4K_INSTRUCT.value: MicrosoftPhi3FoundationModel
|
||||
}
|
||||
|
||||
if model_id not in model_map:
|
||||
raise ValueError(f"Unsupported model type: {model_id}")
|
||||
if model_id.value not in model_map:
|
||||
raise ValueError(f"Unsupported model type: {model_id.value}")
|
||||
|
||||
return model_map[model_id](config)
|
||||
return model_map[model_id.value](config)
|
||||
|
||||
# Factory function to create the appropriate pipeline
|
||||
def create_model_pipeline(model_id: ModelId, model, tokenizer) -> HuggingFacePipeline:
|
||||
@@ -45,12 +45,12 @@ class FoundationModelFactory:
|
||||
# Determine model type from name
|
||||
model_type = None
|
||||
for key in pipeline_classes.keys():
|
||||
if key in model_id:
|
||||
if key in model_id.value:
|
||||
model_type = key
|
||||
break
|
||||
|
||||
if model_type is None:
|
||||
raise ValueError(f"Unsupported model: {model_id}")
|
||||
raise ValueError(f"Unsupported model: {model_id.value}")
|
||||
|
||||
pipeline_class = pipeline_classes[model_type]
|
||||
return pipeline_class(model, tokenizer).create_pipeline()
|
||||
@@ -11,18 +11,19 @@ from src.text_generation.common.model_id import ModelId
|
||||
class MetaLlamaFoundationModel(BaseFoundationModel):
|
||||
"""meta-llama/Llama-3.2-3B-Instruct implementation"""
|
||||
|
||||
MODEL_ID = ModelId.META_LLAMA_3_2_3B_INSTRUCT.value
|
||||
|
||||
def __init__(self, config: MetaLlamaConfig = MetaLlamaConfig()):
|
||||
self.config = config
|
||||
super().__init__()
|
||||
self.MODEL_ID = ModelId.META_LLAMA_3_2_3B_INSTRUCT.value
|
||||
super().__init__(config)
|
||||
|
||||
def _load_model(self) -> None:
|
||||
self.tokenizer = AutoTokenizer.from_pretrained(
|
||||
self.MODEL_ID,
|
||||
self.MODEL_ID.value,
|
||||
local_files_only=self.config.local_files_only
|
||||
)
|
||||
self.model = AutoModelForCausalLM.from_pretrained(
|
||||
self.MODEL_ID,
|
||||
self.MODEL_ID.value,
|
||||
local_files_only=self.config.local_files_only
|
||||
)
|
||||
|
||||
|
||||
@@ -8,18 +8,20 @@ from src.text_generation.common.model_id import ModelId
|
||||
|
||||
class MicrosoftPhi3FoundationModel(BaseFoundationModel):
|
||||
"""Microsoft Phi3 Mini 4K implementation"""
|
||||
|
||||
MODEL_ID = ModelId.MICROSOFT_PHI_3_MINI4K_INSTRUCT
|
||||
|
||||
def __init__(self, config: MicrosoftPhi3Mini4KConfig = MicrosoftPhi3Mini4KConfig()):
|
||||
self.config = config
|
||||
super().__init__()
|
||||
self.MODEL_ID = ModelId.MICROSOFT_PHI_3_MINI4K_INSTRUCT.value
|
||||
super().__init__(config)
|
||||
|
||||
def _load_model(self) -> None:
|
||||
self.tokenizer = AutoTokenizer.from_pretrained(
|
||||
self.MODEL_ID,
|
||||
self.MODEL_ID.value,
|
||||
local_files_only=self.config.local_files_only
|
||||
)
|
||||
self.model = AutoModelForCausalLM.from_pretrained(
|
||||
self.MODEL_ID,
|
||||
self.MODEL_ID.value,
|
||||
local_files_only=self.config.local_files_only
|
||||
)
|
||||
|
||||
|
||||
@@ -4,4 +4,4 @@ from enum import Enum
|
||||
class ModelId(Enum):
|
||||
APPLE_OPENELM_3B_INSTRUCT = "apple/OpenELM-3B-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-onnx"
|
||||
MICROSOFT_PHI_3_MINI4K_INSTRUCT = "microsoft/Phi-3-mini-4k-instruct"
|
||||
@@ -7,15 +7,16 @@ import time
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from src.text_generation.common.model_id import ModelId
|
||||
from src.text_generation.domain.text_generation_completion_result import TextGenerationCompletionResult
|
||||
from src.text_generation.services.logging.abstract_test_run_logging_service import AbstractTestRunLoggingService
|
||||
|
||||
|
||||
class TestRunLoggingService(AbstractTestRunLoggingService):
|
||||
def __init__(self, test_id: int):
|
||||
def __init__(self, test_id: int, model_id: ModelId):
|
||||
self._lock = threading.Lock()
|
||||
timestamp = calendar.timegm(time.gmtime())
|
||||
self.log_file_path = f"./tests/logs/test_{test_id}/test_{test_id}_logs_{timestamp}.json"
|
||||
self.log_file_path = f"./tests/logs/test_{test_id}/{str(model_id.value).replace("/", "_")}/test_{test_id}_logs_{timestamp}.json"
|
||||
self._ensure_log_file_exists()
|
||||
|
||||
def _ensure_log_file_exists(self):
|
||||
|
||||
@@ -43,7 +43,7 @@ class TextGenerationCompletionService(
|
||||
semantic_similarity_service: AbstractSemanticSimilarityService,
|
||||
prompt_injection_example_service: AbstractPromptInjectionExampleService,
|
||||
llm_configuration_introspection_service: AbstractLLMConfigurationIntrospectionService,
|
||||
default_model_type: ModelId = ModelId.MICROSOFT_PHI_3_MINI4K_INSTRUCT.value):
|
||||
default_model_type: ModelId = ModelId.MICROSOFT_PHI_3_MINI4K_INSTRUCT):
|
||||
|
||||
super().__init__()
|
||||
self.constants = Constants()
|
||||
@@ -113,7 +113,7 @@ class TextGenerationCompletionService(
|
||||
|
||||
self._current_model = self.factory.create_model(model_id, config)
|
||||
self._current_model.load()
|
||||
self._current_model_id = model_id
|
||||
self._current_model_id: ModelId = model_id
|
||||
self.foundation_model_pipeline = self._current_model.create_pipeline()
|
||||
|
||||
logger.info(f"Successfully loaded model: {model_id.value}")
|
||||
|
||||
Reference in New Issue
Block a user