Skip to main content

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, OLMo
  • ModuleTypes: 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 serialization
  • torch==2.7.1 - PyTorch for tensor operations
  • numpy==1.26.4 - Numerical computing
  • requests==2.32.4 - HTTP client
  • loguru==0.7.2 - Logging

Optional Dependencies

  • boto3<=1.38.44 - AWS SDK
  • fastapi==0.115.11 - Web framework
  • slack-sdk==3.35.0 - Slack integration
  • transformers==4.52.4 - Hugging Face transformers
  • accelerate==1.4.0 - Hugging Face accelerate
  • gymnasium==1.0.0 - RL environments

Troubleshooting

Common Issues

  1. Import Errors: Ensure you're in the virtual environment and have installed the package correctly.

  2. 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
    
  3. Make Command Not Found: Ensure you have make installed on your system.

  4. 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:

  1. Follow the existing code style (Black, isort, flake8)
  2. Add appropriate type hints
  3. Include unit tests for new functionality
  4. Update documentation for new features
  5. Ensure all tests pass before submitting

License

This package is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

Metadata

Release files for libinephany 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for libinephany 1.3.0
File Size Uploaded Provenance Actions
libinephany-1.3.0.tar.gz 75.7 kB Without provenance Details for libinephany-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for libinephany 1.3.0
File Interpreter ABI Platform Actions
libinephany-1.3.0-py3-none-any.whl Python 3 none any Details for libinephany-1.3.0-py3-none-any.whl

Total release size: 172.8 kB

Release files / libinephany-1.3.0.tar.gz

Download URL libinephany-1.3.0.tar.gz
Size 75.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b72e5317d1d112d4bb98e73125a79f86c9187c9f838d3f92b771b196713c749c
BLAKE2b-256 checksum
How to use checksums
48e89300b49c0edd6158eff96979cee7b7c2f4e475ab2fe9125831b386f2a36c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / libinephany-1.3.0-py3-none-any.whl

Download URL libinephany-1.3.0-py3-none-any.whl
Size 97.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d83d419e903d3d8ee9734a447e51a7509d87c69b2050c3c75fe0b8f8ffd0250
BLAKE2b-256 checksum
How to use checksums
2c4f5c8df78ea42048752efc412e4dc19f215d0078fb667649c85d10bdebfe6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for libinephany 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page