Inephany library containing code commonly used by multiple subpackages.
Project description
Inephany Common Library
The Inephany Common Library (libinephany) is a core utility package that provides shared functionality, data models, and utilities used across multiple Inephany packages. It contains essential components for hyperparameter optimization, model observation, data serialization, and common utilities.
Features
- Pydantic Data Models: Comprehensive schemas for hyperparameters, observations, and API communications
- Utility Functions: Common utilities for PyTorch, optimization, transforms, and more
- Observation System: Tools for collecting and managing model statistics and observations
- Constants and Enums: Standardized constants and enumerations for agent types, model families, and module types
- AWS Integration: Utilities for AWS services integration
- Web Application Utilities: Common web app functionality and endpoints
Installation
Prerequisites
- Python 3.10+
- Make (for build automation)
Ubuntu / Debian
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12
MacOS with brew
brew install python@3.12
For Developers (Monorepo)
If you're working within the Inephany monorepo, the package is already available and will be installed automatically when you run the installation commands in dependent packages.
For Clients (Standalone Installation)
libinephany is available on PyPI and can be installed directly:
pip install libinephany
For development installations with additional dependencies:
pip install libinephany[dev]
Key Components
Pydantic Models
The package provides comprehensive data models for:
- Hyperparameter Configurations:
HParamConfig,HParamConfigs - Observation Models:
ObservationInputs, tensor statistics - API Schemas: Request/response models for client-server communication
- State Management: Hyperparameter states and update callbacks
Utility Functions
Agent Utilities (agent_utils.py)
- Agent ID generation and parsing
- Hyperparameter group management
- Agent type validation
Constants (constants.py)
- Hyperparameter type constants (learning_rate, weight_decay, etc.)
- Agent prefixes and suffixes
- API key headers and timestamp formats
Enums (enums.py)
AgentTypes: Learning rate, weight decay, dropout, etc.ModelFamilies: GPT, BERT, OLMoModuleTypes: Convolutional, attention, linear, embedding
Optimization Utilities (optim_utils.py)
- PyTorch optimizer utilities
- Parameter group management
- Learning rate scheduler utilities
PyTorch Utilities (torch_utils.py)
- Tensor operations
- Model utilities
- Distributed training helpers
Observation System
The observation system provides tools for collecting and managing model statistics:
- StatisticManager: Centralized statistics collection and management
- ObserverPipeline: Configurable observation pipelines
- PipelineCoordinator: Coordinates multiple observers
- StatisticTrackers: Specialized trackers for different metric types
Usage Examples
Basic Import Examples
# Import common constants
from libinephany.utils.constants import LEARNING_RATE, WEIGHT_DECAY, AGENT_PREFIX_LR
# Import enums
from libinephany.utils.enums import AgentTypes, ModelFamilies, ModuleTypes
# Import utility functions
from libinephany.utils import agent_utils, optim_utils, torch_utils
# Import data models
from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
from libinephany.pydantic_models.schemas.response_schemas import ClientPolicySchemaResponse
Working with Agent Types
from libinephany.utils.enums import AgentTypes
# Check if an agent type is valid
agent_type = "learning_rate"
if agent_type in [agent.value for agent in AgentTypes]:
print(f"{agent_type} is a valid agent type")
# Get agent type by index
lr_agent = AgentTypes.get_from_index(0) # LearningRateAgent
Using Constants
from libinephany.utils.constants import AGENT_PREFIX_LR, LEARNING_RATE
# Generate agent ID
agent_id = f"{AGENT_PREFIX_LR}_agent_001"
hyperparam_type = LEARNING_RATE
Working with Pydantic Models
from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
# Create a hyperparameter configuration
config = HParamConfig(
name="learning_rate",
value=0.001,
min_value=1e-6,
max_value=1.0
)
Development
Running Tests
make execute-unit-tests
Code Quality
make lint # Run all linters
make fix-black # Fix formatting
make fix-isort # Fix imports
Version Management
make increment-patch-version # Increment patch version
make increment-minor-version # Increment minor version
make increment-major-version # Increment major version
make increment-pre-release-version # Increment pre-release version
Dependencies
Core Dependencies
pydantic==2.8.2- Data validation and serializationtorch==2.7.1- PyTorch for tensor operationsnumpy==1.26.4- Numerical computingrequests==2.32.4- HTTP clientloguru==0.7.2- Logging
Optional Dependencies
boto3<=1.38.44- AWS SDKfastapi==0.115.11- Web frameworkslack-sdk==3.35.0- Slack integrationtransformers==4.52.4- Hugging Face transformersaccelerate==1.4.0- Hugging Face accelerategymnasium==1.0.0- RL environments
Troubleshooting
Common Issues
-
Import Errors: Ensure you're in the virtual environment and have installed the package correctly.
-
Version Conflicts: If you encounter dependency conflicts, try installing in a fresh virtual environment:
python -m venv fresh_env source fresh_env/bin/activate make install-dev
-
Make Command Not Found: Ensure you have
makeinstalled on your system. -
Python Version Issues: This package requires Python 3.12+. Ensure you're using the correct version.
Getting Help
- Check the example scripts in the repository
- Review the test files for usage examples
- Ensure all dependencies are installed correctly
- Verify your Python version is 3.12+
Contributing
When contributing to libinephany:
- Follow the existing code style (Black, isort, flake8)
- Add appropriate type hints
- Include unit tests for new functionality
- Update documentation for new features
- Ensure all tests pass before submitting
License
This package is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libinephany-1.1.25.tar.gz.
File metadata
- Download URL: libinephany-1.1.25.tar.gz
- Upload date:
- Size: 77.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05d96885aef1c5dfd125a8a8ffce4f4a552c5feda73ff07558cecb0414690006
|
|
| MD5 |
b32ff3df6cb131ecb9ef630fabc9bf7b
|
|
| BLAKE2b-256 |
71fb8adc6343c8578fdceb6c63c2c4db2914652a8e4d1d2feefa13bdf03383d5
|
File details
Details for the file libinephany-1.1.25-py3-none-any.whl.
File metadata
- Download URL: libinephany-1.1.25-py3-none-any.whl
- Upload date:
- Size: 99.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49d27c3887ed418e0a68a0abc5aaad7151d03d68701ec7913bb6ca590634c5ed
|
|
| MD5 |
2e35c486e1936d3a0dd0451db7015b55
|
|
| BLAKE2b-256 |
28adb1e23d4a0ed88f8eed70b680ac4609bc7da0d2993baac710890d01b9432b
|