Save and load UQ Ensemble#61
Merged
Merged
Conversation
added 2 commits
June 17, 2025 03:49
mohitcek
approved these changes
Jun 18, 2025
dylanbouchard
requested changes
Jun 22, 2025
| llm_params[param_name] = env_value | ||
| else: | ||
| # Try common environment variable names as fallback | ||
| common_env_vars = { |
Collaborator
There was a problem hiding this comment.
As discussed, let's remove storing/loading of sensitive credentials and rely on proper naming conventions in environment variables.
| " azure_endpoint=os.getenv(\"API_BASE\"),\n", | ||
| " openai_api_type=os.getenv(\"API_TYPE\"),\n", | ||
| " openai_api_version=os.getenv(\"API_VERSION\"),\n", | ||
| " deployment_name=os.getenv(\"AZURECHATOPENAI_DEPLOYMENT_NAME\"),\n", |
Collaborator
There was a problem hiding this comment.
Let's update the naming convention for .env files so we don't have to directly specify these in the constructor. Ideally we can have something like this in all notebooks instead:
# Use of AzureChatOpenAI requires .env file be populated with AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
from langchain_openai import AzureChatOpenAI
llm = AzureChatOpenAI(
deployment_name="gpt-4o",
openai_api_version='2024-02-15-preview',
openai_api_type='azure',
temperature=1, # User to set temperature
)
dylanbouchard
approved these changes
Jun 25, 2025
dylanbouchard
left a comment
Collaborator
There was a problem hiding this comment.
Amazing work, Viren!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Save/Load Configuration Functionality to UQEnsemble
Summary
This PR adds the ability to save and load UQEnsemble configurations, enabling users to persist tuned weights, thresholds, and component configurations for reproducible experiments and model deployment.
Changes Made
New Methods Added
save_llm_config(): Helper function to extract and serialize LLM configuration parametersload_llm_config(): Helper function to recreate LLM instances from saved configurationsave_config(): Instance method to save ensemble configuration to JSON fileload_config(): Class method to create UQEnsemble instance from saved configurationKey Features
Parameter Exclusion
The system excludes the following from saved configurations:
internal_attrsset (e.g.,config_specs,lc_attributes,model_config)endpoint_attrsset (e.g.,base_url,endpoint,azure_endpoint,api_base)Environment Variables
API credentials must be set in environment variables for the load to work properly. The LLM modules automatically read standard environment variable names such as:
AZURE_OPENAI_API_KEY,AZURE_OPENAI_ENDPOINTfor Azure OpenAIGOOGLE_APPLICATION_CREDENTIALSfor Google Vertex AIConfiguration Format
The saved JSON includes:
weights: Ensemble component weights (typically from tuning)thresh: Decision thresholdcomponents: List of scorer components (named strings or serialized LLM references)llm_config: Main LLM configuration for recreationllm_scorers: Configurations for LLM-based scorer componentsExample Configuration
{ "weights": [ 0.22517161424882978, 0.5256472050407895, 0.20544462057286958, 0.04343460765924121, 0.00030195247826969915 ], "thresh": 0.85, "components": [ "exact_match", "noncontradiction", "normalized_probability", "judge_1", "judge_2" ], "llm_config": { "class_name": "ChatVertexAI", "module": "langchain_google_vertexai.chat_models", "convert_system_message_to_human": false, "default_metadata": [], "endpoint_version": "v1beta1", "full_model_name": "projects/anbc-dev-csr-va/locations/us-central1/publishers/google/models/gemini-1.5-flash", "location": "us-central1", "logprobs": true, "max_retries": 6, "model_family": "2", "model_name": "gemini-1.5-flash", "n": 1, "perform_literal_eval_on_string_raw_content": true, "project": "anbc-dev-csr-va", "request_parallelism": 5, "streaming": false, "verbose": false }, "llm_scorers": { "judge_1": { "class_name": "ChatVertexAI", "module": "langchain_google_vertexai.chat_models", "convert_system_message_to_human": false, "default_metadata": [], "endpoint_version": "v1beta1", "full_model_name": "projects/anbc-dev-csr-va/locations/us-central1/publishers/google/models/gemini-1.5-flash", "location": "us-central1", "logprobs": true, "max_retries": 6, "model_family": "2", "model_name": "gemini-1.5-flash", "n": 1, "perform_literal_eval_on_string_raw_content": true, "project": "anbc-dev-csr-va", "request_parallelism": 5, "streaming": false, "verbose": false }, "judge_2": { "class_name": "AzureChatOpenAI", "module": "langchain_openai.chat_models.azure", "deployment_name": "gpt-4o", "model_version": "", "openai_api_type": "azure", "openai_api_version": "2024-02-15-preview", "streaming": false, "temperature": 1.0, "verbose": false } } }Usage
Benefits
Technical Notes
Dependencies