libinephany 0.13.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libinephany-0.13.1/CODE_VERSION.cfg +1 -0
- libinephany-0.13.1/LICENSE +11 -0
- libinephany-0.13.1/MANIFEST.in +7 -0
- libinephany-0.13.1/PKG-INFO +282 -0
- libinephany-0.13.1/README.md +247 -0
- libinephany-0.13.1/libinephany/__init__.py +0 -0
- libinephany-0.13.1/libinephany/aws/__init__.py +0 -0
- libinephany-0.13.1/libinephany/aws/s3_functions.py +57 -0
- libinephany-0.13.1/libinephany/observations/__init__.py +0 -0
- libinephany-0.13.1/libinephany/observations/observation_utils.py +243 -0
- libinephany-0.13.1/libinephany/observations/observer_pipeline.py +307 -0
- libinephany-0.13.1/libinephany/observations/observers/__init__.py +0 -0
- libinephany-0.13.1/libinephany/observations/observers/base_observers.py +418 -0
- libinephany-0.13.1/libinephany/observations/observers/global_observers.py +988 -0
- libinephany-0.13.1/libinephany/observations/observers/local_observers.py +982 -0
- libinephany-0.13.1/libinephany/observations/observers/observer_containers.py +270 -0
- libinephany-0.13.1/libinephany/observations/pipeline_coordinator.py +198 -0
- libinephany-0.13.1/libinephany/observations/post_processors/__init__.py +0 -0
- libinephany-0.13.1/libinephany/observations/post_processors/postprocessors.py +153 -0
- libinephany-0.13.1/libinephany/observations/statistic_manager.py +217 -0
- libinephany-0.13.1/libinephany/observations/statistic_trackers.py +876 -0
- libinephany-0.13.1/libinephany/pydantic_models/__init__.py +0 -0
- libinephany-0.13.1/libinephany/pydantic_models/configs/__init__.py +0 -0
- libinephany-0.13.1/libinephany/pydantic_models/configs/hyperparameter_configs.py +387 -0
- libinephany-0.13.1/libinephany/pydantic_models/configs/observer_config.py +43 -0
- libinephany-0.13.1/libinephany/pydantic_models/configs/outer_model_config.py +32 -0
- libinephany-0.13.1/libinephany/pydantic_models/schemas/__init__.py +0 -0
- libinephany-0.13.1/libinephany/pydantic_models/schemas/agent_info.py +65 -0
- libinephany-0.13.1/libinephany/pydantic_models/schemas/inner_task_profile.py +284 -0
- libinephany-0.13.1/libinephany/pydantic_models/schemas/observation_models.py +61 -0
- libinephany-0.13.1/libinephany/pydantic_models/schemas/request_schemas.py +45 -0
- libinephany-0.13.1/libinephany/pydantic_models/schemas/response_schemas.py +50 -0
- libinephany-0.13.1/libinephany/pydantic_models/schemas/tensor_statistics.py +254 -0
- libinephany-0.13.1/libinephany/pydantic_models/states/__init__.py +0 -0
- libinephany-0.13.1/libinephany/pydantic_models/states/hyperparameter_states.py +808 -0
- libinephany-0.13.1/libinephany/utils/__init__.py +0 -0
- libinephany-0.13.1/libinephany/utils/agent_utils.py +82 -0
- libinephany-0.13.1/libinephany/utils/asyncio_worker.py +87 -0
- libinephany-0.13.1/libinephany/utils/backend_statuses.py +20 -0
- libinephany-0.13.1/libinephany/utils/constants.py +76 -0
- libinephany-0.13.1/libinephany/utils/directory_utils.py +41 -0
- libinephany-0.13.1/libinephany/utils/dropout_utils.py +92 -0
- libinephany-0.13.1/libinephany/utils/enums.py +90 -0
- libinephany-0.13.1/libinephany/utils/error_severities.py +46 -0
- libinephany-0.13.1/libinephany/utils/exceptions.py +60 -0
- libinephany-0.13.1/libinephany/utils/import_utils.py +43 -0
- libinephany-0.13.1/libinephany/utils/optim_utils.py +239 -0
- libinephany-0.13.1/libinephany/utils/random_seeds.py +55 -0
- libinephany-0.13.1/libinephany/utils/samplers.py +341 -0
- libinephany-0.13.1/libinephany/utils/standardizers.py +217 -0
- libinephany-0.13.1/libinephany/utils/torch_distributed_utils.py +85 -0
- libinephany-0.13.1/libinephany/utils/torch_utils.py +77 -0
- libinephany-0.13.1/libinephany/utils/transforms.py +104 -0
- libinephany-0.13.1/libinephany/utils/typing.py +15 -0
- libinephany-0.13.1/libinephany/web_apps/__init__.py +0 -0
- libinephany-0.13.1/libinephany/web_apps/error_logger.py +421 -0
- libinephany-0.13.1/libinephany/web_apps/web_app_utils.py +123 -0
- libinephany-0.13.1/libinephany.egg-info/PKG-INFO +282 -0
- libinephany-0.13.1/libinephany.egg-info/SOURCES.txt +64 -0
- libinephany-0.13.1/libinephany.egg-info/dependency_links.txt +1 -0
- libinephany-0.13.1/libinephany.egg-info/requires.txt +26 -0
- libinephany-0.13.1/libinephany.egg-info/top_level.txt +1 -0
- libinephany-0.13.1/pyproject.toml +102 -0
- libinephany-0.13.1/requirements.txt +16 -0
- libinephany-0.13.1/setup.cfg +4 -0
- libinephany-0.13.1/setup.py +61 -0
@@ -0,0 +1 @@
|
|
1
|
+
0.13.1
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Limited Evaluation License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Inephany Ltd
|
4
|
+
|
5
|
+
This software is provided to selected recipients for non-commercial evaluation
|
6
|
+
purposes only. You may use, modify, and share this software internally within
|
7
|
+
your organization, but you may not use it for any commercial purpose, including
|
8
|
+
selling, licensing, or incorporating it into a commercial product or service,
|
9
|
+
without explicit written permission from Inephany Ltd.
|
10
|
+
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
@@ -0,0 +1,282 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: libinephany
|
3
|
+
Version: 0.13.1
|
4
|
+
Summary: Inephany library containing code commonly used by multiple subpackages.
|
5
|
+
Requires-Python: >=3.6
|
6
|
+
Description-Content-Type: text/markdown
|
7
|
+
License-File: LICENSE
|
8
|
+
Requires-Dist: pytest<9.0.0,>=7.0.0
|
9
|
+
Requires-Dist: pytest-mock<4.0.0,>=3.10.0
|
10
|
+
Requires-Dist: pytest-asyncio<0.26.0,>=0.21.0
|
11
|
+
Requires-Dist: pydantic<3.0.0,>=2.5.0
|
12
|
+
Requires-Dist: loguru<0.8.0,>=0.7.0
|
13
|
+
Requires-Dist: requests<3.0.0,>=2.28.0
|
14
|
+
Requires-Dist: numpy<2.0.0,>=1.24.0
|
15
|
+
Requires-Dist: slack-sdk<4.0.0,>=3.20.0
|
16
|
+
Requires-Dist: boto3<2.0.0,>=1.26.0
|
17
|
+
Requires-Dist: fastapi<0.116.0,>=0.100.0
|
18
|
+
Requires-Dist: aiohttp<4.0.0,>=3.8.0
|
19
|
+
Requires-Dist: torch<2.8.0,>=2.1.0
|
20
|
+
Requires-Dist: transformers<4.48.3,>=4.30.0
|
21
|
+
Requires-Dist: pandas<3.0.0,>=2.0.0
|
22
|
+
Requires-Dist: accelerate<2.0.0,>=0.20.0
|
23
|
+
Requires-Dist: gymnasium<2.0.0,>=0.29.0
|
24
|
+
Provides-Extra: dev
|
25
|
+
Requires-Dist: bump-my-version==0.11.0; extra == "dev"
|
26
|
+
Requires-Dist: black==24.4.2; extra == "dev"
|
27
|
+
Requires-Dist: isort==5.9.3; extra == "dev"
|
28
|
+
Requires-Dist: flake8==7.1.0; extra == "dev"
|
29
|
+
Requires-Dist: pre-commit==4.0.1; extra == "dev"
|
30
|
+
Requires-Dist: mypy==1.13.0; extra == "dev"
|
31
|
+
Requires-Dist: types-PyYAML==6.0.12.20240808; extra == "dev"
|
32
|
+
Requires-Dist: typeguard==4.3.0; extra == "dev"
|
33
|
+
Dynamic: license-file
|
34
|
+
Dynamic: requires-python
|
35
|
+
|
36
|
+
# Inephany Common Library
|
37
|
+
|
38
|
+
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.
|
39
|
+
|
40
|
+
## Features
|
41
|
+
|
42
|
+
- **Pydantic Data Models**: Comprehensive schemas for hyperparameters, observations, and API communications
|
43
|
+
- **Utility Functions**: Common utilities for PyTorch, optimization, transforms, and more
|
44
|
+
- **Observation System**: Tools for collecting and managing model statistics and observations
|
45
|
+
- **Constants and Enums**: Standardized constants and enumerations for agent types, model families, and module types
|
46
|
+
- **AWS Integration**: Utilities for AWS services integration
|
47
|
+
- **Web Application Utilities**: Common web app functionality and endpoints
|
48
|
+
|
49
|
+
## Installation
|
50
|
+
|
51
|
+
### Prerequisites
|
52
|
+
|
53
|
+
- Python 3.12+
|
54
|
+
- Make (for build automation)
|
55
|
+
|
56
|
+
#### Ubuntu / Debian
|
57
|
+
```bash
|
58
|
+
sudo add-apt-repository ppa:deadsnakes/ppa
|
59
|
+
sudo apt update
|
60
|
+
sudo apt install python3.12 make
|
61
|
+
```
|
62
|
+
|
63
|
+
#### MacOS with brew
|
64
|
+
```bash
|
65
|
+
brew install python@3.12
|
66
|
+
brew install make
|
67
|
+
```
|
68
|
+
|
69
|
+
### For Developers (Monorepo)
|
70
|
+
|
71
|
+
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.
|
72
|
+
|
73
|
+
### For Clients (Standalone Installation)
|
74
|
+
|
75
|
+
Since `libinephany` is not yet published on PyPI, you'll need to build and install it manually from source. Follow these steps:
|
76
|
+
|
77
|
+
1. **Create a new virtual environment**
|
78
|
+
```bash
|
79
|
+
python3.12 -m venv myenv
|
80
|
+
```
|
81
|
+
|
82
|
+
2. **Activate the virtual environment**
|
83
|
+
```bash
|
84
|
+
source myenv/bin/activate
|
85
|
+
```
|
86
|
+
|
87
|
+
3. **Install Build Tools**
|
88
|
+
```bash
|
89
|
+
python -m pip install --upgrade pip setuptools build wheel
|
90
|
+
```
|
91
|
+
|
92
|
+
4. **Change into the `libinephany` directory**
|
93
|
+
|
94
|
+
5. **Build and install `libinephany`**
|
95
|
+
```bash
|
96
|
+
python -m build
|
97
|
+
pip install dist/libinephany-<version>-py3-none-any.whl
|
98
|
+
```
|
99
|
+
Replace `<version>` with the actual version number of the built wheel.
|
100
|
+
|
101
|
+
**Note**: Once `libinephany` is published to PyPI, you'll be able to install it with `pip install libinephany`.
|
102
|
+
|
103
|
+
## Key Components
|
104
|
+
|
105
|
+
### Pydantic Models
|
106
|
+
|
107
|
+
The package provides comprehensive data models for:
|
108
|
+
|
109
|
+
- **Hyperparameter Configurations**: `HParamConfig`, `HParamConfigs`
|
110
|
+
- **Observation Models**: `ObservationInputs`, tensor statistics
|
111
|
+
- **API Schemas**: Request/response models for client-server communication
|
112
|
+
- **State Management**: Hyperparameter states and update callbacks
|
113
|
+
|
114
|
+
### Utility Functions
|
115
|
+
|
116
|
+
#### Agent Utilities (`agent_utils.py`)
|
117
|
+
- Agent ID generation and parsing
|
118
|
+
- Hyperparameter group management
|
119
|
+
- Agent type validation
|
120
|
+
|
121
|
+
#### Constants (`constants.py`)
|
122
|
+
- Hyperparameter type constants (learning_rate, weight_decay, etc.)
|
123
|
+
- Agent prefixes and suffixes
|
124
|
+
- API key headers and timestamp formats
|
125
|
+
|
126
|
+
#### Enums (`enums.py`)
|
127
|
+
- `AgentTypes`: Learning rate, weight decay, dropout, etc.
|
128
|
+
- `ModelFamilies`: GPT, BERT, OLMo
|
129
|
+
- `ModuleTypes`: Convolutional, attention, linear, embedding
|
130
|
+
|
131
|
+
#### Optimization Utilities (`optim_utils.py`)
|
132
|
+
- PyTorch optimizer utilities
|
133
|
+
- Parameter group management
|
134
|
+
- Learning rate scheduler utilities
|
135
|
+
|
136
|
+
#### PyTorch Utilities (`torch_utils.py`)
|
137
|
+
- Tensor operations
|
138
|
+
- Model utilities
|
139
|
+
- Distributed training helpers
|
140
|
+
|
141
|
+
### Observation System
|
142
|
+
|
143
|
+
The observation system provides tools for collecting and managing model statistics:
|
144
|
+
|
145
|
+
- **StatisticManager**: Centralized statistics collection and management
|
146
|
+
- **ObserverPipeline**: Configurable observation pipelines
|
147
|
+
- **PipelineCoordinator**: Coordinates multiple observers
|
148
|
+
- **StatisticTrackers**: Specialized trackers for different metric types
|
149
|
+
|
150
|
+
## Usage Examples
|
151
|
+
|
152
|
+
### Basic Import Examples
|
153
|
+
|
154
|
+
```python
|
155
|
+
# Import common constants
|
156
|
+
from libinephany.utils.constants import LEARNING_RATE, WEIGHT_DECAY, AGENT_PREFIX_LR
|
157
|
+
|
158
|
+
# Import enums
|
159
|
+
from libinephany.utils.enums import AgentTypes, ModelFamilies, ModuleTypes
|
160
|
+
|
161
|
+
# Import utility functions
|
162
|
+
from libinephany.utils import agent_utils, optim_utils, torch_utils
|
163
|
+
|
164
|
+
# Import data models
|
165
|
+
from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
|
166
|
+
from libinephany.pydantic_models.schemas.response_schemas import ClientPolicySchemaResponse
|
167
|
+
```
|
168
|
+
|
169
|
+
### Working with Agent Types
|
170
|
+
|
171
|
+
```python
|
172
|
+
from libinephany.utils.enums import AgentTypes
|
173
|
+
|
174
|
+
# Check if an agent type is valid
|
175
|
+
agent_type = "learning_rate"
|
176
|
+
if agent_type in [agent.value for agent in AgentTypes]:
|
177
|
+
print(f"{agent_type} is a valid agent type")
|
178
|
+
|
179
|
+
# Get agent type by index
|
180
|
+
lr_agent = AgentTypes.get_from_index(0) # LearningRateAgent
|
181
|
+
```
|
182
|
+
|
183
|
+
### Using Constants
|
184
|
+
|
185
|
+
```python
|
186
|
+
from libinephany.utils.constants import AGENT_PREFIX_LR, LEARNING_RATE
|
187
|
+
|
188
|
+
# Generate agent ID
|
189
|
+
agent_id = f"{AGENT_PREFIX_LR}_agent_001"
|
190
|
+
hyperparam_type = LEARNING_RATE
|
191
|
+
```
|
192
|
+
|
193
|
+
### Working with Pydantic Models
|
194
|
+
|
195
|
+
```python
|
196
|
+
from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
|
197
|
+
|
198
|
+
# Create a hyperparameter configuration
|
199
|
+
config = HParamConfig(
|
200
|
+
name="learning_rate",
|
201
|
+
value=0.001,
|
202
|
+
min_value=1e-6,
|
203
|
+
max_value=1.0
|
204
|
+
)
|
205
|
+
```
|
206
|
+
|
207
|
+
## Development
|
208
|
+
|
209
|
+
### Running Tests
|
210
|
+
```bash
|
211
|
+
make execute-unit-tests
|
212
|
+
```
|
213
|
+
|
214
|
+
### Code Quality
|
215
|
+
```bash
|
216
|
+
make lint # Run all linters
|
217
|
+
make fix-black # Fix formatting
|
218
|
+
make fix-isort # Fix imports
|
219
|
+
```
|
220
|
+
|
221
|
+
### Version Management
|
222
|
+
```bash
|
223
|
+
make increment-patch-version # Increment patch version
|
224
|
+
make increment-minor-version # Increment minor version
|
225
|
+
make increment-major-version # Increment major version
|
226
|
+
make increment-pre-release-version # Increment pre-release version
|
227
|
+
```
|
228
|
+
|
229
|
+
## Dependencies
|
230
|
+
|
231
|
+
### Core Dependencies
|
232
|
+
- `pydantic==2.8.2` - Data validation and serialization
|
233
|
+
- `torch==2.7.1` - PyTorch for tensor operations
|
234
|
+
- `numpy==1.26.4` - Numerical computing
|
235
|
+
- `requests==2.32.4` - HTTP client
|
236
|
+
- `loguru==0.7.2` - Logging
|
237
|
+
|
238
|
+
### Optional Dependencies
|
239
|
+
- `boto3<=1.38.44` - AWS SDK
|
240
|
+
- `fastapi==0.115.11` - Web framework
|
241
|
+
- `slack-sdk==3.35.0` - Slack integration
|
242
|
+
- `transformers==4.52.4` - Hugging Face transformers
|
243
|
+
- `accelerate==1.4.0` - Hugging Face accelerate
|
244
|
+
- `gymnasium==1.0.0` - RL environments
|
245
|
+
|
246
|
+
## Troubleshooting
|
247
|
+
|
248
|
+
### Common Issues
|
249
|
+
|
250
|
+
1. **Import Errors**: Ensure you're in the virtual environment and have installed the package correctly.
|
251
|
+
|
252
|
+
2. **Version Conflicts**: If you encounter dependency conflicts, try installing in a fresh virtual environment:
|
253
|
+
```bash
|
254
|
+
python -m venv fresh_env
|
255
|
+
source fresh_env/bin/activate
|
256
|
+
make install-dev
|
257
|
+
```
|
258
|
+
|
259
|
+
3. **Make Command Not Found**: Ensure you have `make` installed on your system.
|
260
|
+
|
261
|
+
4. **Python Version Issues**: This package requires Python 3.12+. Ensure you're using the correct version.
|
262
|
+
|
263
|
+
### Getting Help
|
264
|
+
|
265
|
+
- Check the example scripts in the repository
|
266
|
+
- Review the test files for usage examples
|
267
|
+
- Ensure all dependencies are installed correctly
|
268
|
+
- Verify your Python version is 3.12+
|
269
|
+
|
270
|
+
## Contributing
|
271
|
+
|
272
|
+
When contributing to `libinephany`:
|
273
|
+
|
274
|
+
1. Follow the existing code style (Black, isort, flake8)
|
275
|
+
2. Add appropriate type hints
|
276
|
+
3. Include unit tests for new functionality
|
277
|
+
4. Update documentation for new features
|
278
|
+
5. Ensure all tests pass before submitting
|
279
|
+
|
280
|
+
## License
|
281
|
+
|
282
|
+
This package is part of the Inephany ecosystem and is subject to the same licensing terms as other Inephany packages.
|
@@ -0,0 +1,247 @@
|
|
1
|
+
# Inephany Common Library
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **Pydantic Data Models**: Comprehensive schemas for hyperparameters, observations, and API communications
|
8
|
+
- **Utility Functions**: Common utilities for PyTorch, optimization, transforms, and more
|
9
|
+
- **Observation System**: Tools for collecting and managing model statistics and observations
|
10
|
+
- **Constants and Enums**: Standardized constants and enumerations for agent types, model families, and module types
|
11
|
+
- **AWS Integration**: Utilities for AWS services integration
|
12
|
+
- **Web Application Utilities**: Common web app functionality and endpoints
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
### Prerequisites
|
17
|
+
|
18
|
+
- Python 3.12+
|
19
|
+
- Make (for build automation)
|
20
|
+
|
21
|
+
#### Ubuntu / Debian
|
22
|
+
```bash
|
23
|
+
sudo add-apt-repository ppa:deadsnakes/ppa
|
24
|
+
sudo apt update
|
25
|
+
sudo apt install python3.12 make
|
26
|
+
```
|
27
|
+
|
28
|
+
#### MacOS with brew
|
29
|
+
```bash
|
30
|
+
brew install python@3.12
|
31
|
+
brew install make
|
32
|
+
```
|
33
|
+
|
34
|
+
### For Developers (Monorepo)
|
35
|
+
|
36
|
+
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.
|
37
|
+
|
38
|
+
### For Clients (Standalone Installation)
|
39
|
+
|
40
|
+
Since `libinephany` is not yet published on PyPI, you'll need to build and install it manually from source. Follow these steps:
|
41
|
+
|
42
|
+
1. **Create a new virtual environment**
|
43
|
+
```bash
|
44
|
+
python3.12 -m venv myenv
|
45
|
+
```
|
46
|
+
|
47
|
+
2. **Activate the virtual environment**
|
48
|
+
```bash
|
49
|
+
source myenv/bin/activate
|
50
|
+
```
|
51
|
+
|
52
|
+
3. **Install Build Tools**
|
53
|
+
```bash
|
54
|
+
python -m pip install --upgrade pip setuptools build wheel
|
55
|
+
```
|
56
|
+
|
57
|
+
4. **Change into the `libinephany` directory**
|
58
|
+
|
59
|
+
5. **Build and install `libinephany`**
|
60
|
+
```bash
|
61
|
+
python -m build
|
62
|
+
pip install dist/libinephany-<version>-py3-none-any.whl
|
63
|
+
```
|
64
|
+
Replace `<version>` with the actual version number of the built wheel.
|
65
|
+
|
66
|
+
**Note**: Once `libinephany` is published to PyPI, you'll be able to install it with `pip install libinephany`.
|
67
|
+
|
68
|
+
## Key Components
|
69
|
+
|
70
|
+
### Pydantic Models
|
71
|
+
|
72
|
+
The package provides comprehensive data models for:
|
73
|
+
|
74
|
+
- **Hyperparameter Configurations**: `HParamConfig`, `HParamConfigs`
|
75
|
+
- **Observation Models**: `ObservationInputs`, tensor statistics
|
76
|
+
- **API Schemas**: Request/response models for client-server communication
|
77
|
+
- **State Management**: Hyperparameter states and update callbacks
|
78
|
+
|
79
|
+
### Utility Functions
|
80
|
+
|
81
|
+
#### Agent Utilities (`agent_utils.py`)
|
82
|
+
- Agent ID generation and parsing
|
83
|
+
- Hyperparameter group management
|
84
|
+
- Agent type validation
|
85
|
+
|
86
|
+
#### Constants (`constants.py`)
|
87
|
+
- Hyperparameter type constants (learning_rate, weight_decay, etc.)
|
88
|
+
- Agent prefixes and suffixes
|
89
|
+
- API key headers and timestamp formats
|
90
|
+
|
91
|
+
#### Enums (`enums.py`)
|
92
|
+
- `AgentTypes`: Learning rate, weight decay, dropout, etc.
|
93
|
+
- `ModelFamilies`: GPT, BERT, OLMo
|
94
|
+
- `ModuleTypes`: Convolutional, attention, linear, embedding
|
95
|
+
|
96
|
+
#### Optimization Utilities (`optim_utils.py`)
|
97
|
+
- PyTorch optimizer utilities
|
98
|
+
- Parameter group management
|
99
|
+
- Learning rate scheduler utilities
|
100
|
+
|
101
|
+
#### PyTorch Utilities (`torch_utils.py`)
|
102
|
+
- Tensor operations
|
103
|
+
- Model utilities
|
104
|
+
- Distributed training helpers
|
105
|
+
|
106
|
+
### Observation System
|
107
|
+
|
108
|
+
The observation system provides tools for collecting and managing model statistics:
|
109
|
+
|
110
|
+
- **StatisticManager**: Centralized statistics collection and management
|
111
|
+
- **ObserverPipeline**: Configurable observation pipelines
|
112
|
+
- **PipelineCoordinator**: Coordinates multiple observers
|
113
|
+
- **StatisticTrackers**: Specialized trackers for different metric types
|
114
|
+
|
115
|
+
## Usage Examples
|
116
|
+
|
117
|
+
### Basic Import Examples
|
118
|
+
|
119
|
+
```python
|
120
|
+
# Import common constants
|
121
|
+
from libinephany.utils.constants import LEARNING_RATE, WEIGHT_DECAY, AGENT_PREFIX_LR
|
122
|
+
|
123
|
+
# Import enums
|
124
|
+
from libinephany.utils.enums import AgentTypes, ModelFamilies, ModuleTypes
|
125
|
+
|
126
|
+
# Import utility functions
|
127
|
+
from libinephany.utils import agent_utils, optim_utils, torch_utils
|
128
|
+
|
129
|
+
# Import data models
|
130
|
+
from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
|
131
|
+
from libinephany.pydantic_models.schemas.response_schemas import ClientPolicySchemaResponse
|
132
|
+
```
|
133
|
+
|
134
|
+
### Working with Agent Types
|
135
|
+
|
136
|
+
```python
|
137
|
+
from libinephany.utils.enums import AgentTypes
|
138
|
+
|
139
|
+
# Check if an agent type is valid
|
140
|
+
agent_type = "learning_rate"
|
141
|
+
if agent_type in [agent.value for agent in AgentTypes]:
|
142
|
+
print(f"{agent_type} is a valid agent type")
|
143
|
+
|
144
|
+
# Get agent type by index
|
145
|
+
lr_agent = AgentTypes.get_from_index(0) # LearningRateAgent
|
146
|
+
```
|
147
|
+
|
148
|
+
### Using Constants
|
149
|
+
|
150
|
+
```python
|
151
|
+
from libinephany.utils.constants import AGENT_PREFIX_LR, LEARNING_RATE
|
152
|
+
|
153
|
+
# Generate agent ID
|
154
|
+
agent_id = f"{AGENT_PREFIX_LR}_agent_001"
|
155
|
+
hyperparam_type = LEARNING_RATE
|
156
|
+
```
|
157
|
+
|
158
|
+
### Working with Pydantic Models
|
159
|
+
|
160
|
+
```python
|
161
|
+
from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
|
162
|
+
|
163
|
+
# Create a hyperparameter configuration
|
164
|
+
config = HParamConfig(
|
165
|
+
name="learning_rate",
|
166
|
+
value=0.001,
|
167
|
+
min_value=1e-6,
|
168
|
+
max_value=1.0
|
169
|
+
)
|
170
|
+
```
|
171
|
+
|
172
|
+
## Development
|
173
|
+
|
174
|
+
### Running Tests
|
175
|
+
```bash
|
176
|
+
make execute-unit-tests
|
177
|
+
```
|
178
|
+
|
179
|
+
### Code Quality
|
180
|
+
```bash
|
181
|
+
make lint # Run all linters
|
182
|
+
make fix-black # Fix formatting
|
183
|
+
make fix-isort # Fix imports
|
184
|
+
```
|
185
|
+
|
186
|
+
### Version Management
|
187
|
+
```bash
|
188
|
+
make increment-patch-version # Increment patch version
|
189
|
+
make increment-minor-version # Increment minor version
|
190
|
+
make increment-major-version # Increment major version
|
191
|
+
make increment-pre-release-version # Increment pre-release version
|
192
|
+
```
|
193
|
+
|
194
|
+
## Dependencies
|
195
|
+
|
196
|
+
### Core Dependencies
|
197
|
+
- `pydantic==2.8.2` - Data validation and serialization
|
198
|
+
- `torch==2.7.1` - PyTorch for tensor operations
|
199
|
+
- `numpy==1.26.4` - Numerical computing
|
200
|
+
- `requests==2.32.4` - HTTP client
|
201
|
+
- `loguru==0.7.2` - Logging
|
202
|
+
|
203
|
+
### Optional Dependencies
|
204
|
+
- `boto3<=1.38.44` - AWS SDK
|
205
|
+
- `fastapi==0.115.11` - Web framework
|
206
|
+
- `slack-sdk==3.35.0` - Slack integration
|
207
|
+
- `transformers==4.52.4` - Hugging Face transformers
|
208
|
+
- `accelerate==1.4.0` - Hugging Face accelerate
|
209
|
+
- `gymnasium==1.0.0` - RL environments
|
210
|
+
|
211
|
+
## Troubleshooting
|
212
|
+
|
213
|
+
### Common Issues
|
214
|
+
|
215
|
+
1. **Import Errors**: Ensure you're in the virtual environment and have installed the package correctly.
|
216
|
+
|
217
|
+
2. **Version Conflicts**: If you encounter dependency conflicts, try installing in a fresh virtual environment:
|
218
|
+
```bash
|
219
|
+
python -m venv fresh_env
|
220
|
+
source fresh_env/bin/activate
|
221
|
+
make install-dev
|
222
|
+
```
|
223
|
+
|
224
|
+
3. **Make Command Not Found**: Ensure you have `make` installed on your system.
|
225
|
+
|
226
|
+
4. **Python Version Issues**: This package requires Python 3.12+. Ensure you're using the correct version.
|
227
|
+
|
228
|
+
### Getting Help
|
229
|
+
|
230
|
+
- Check the example scripts in the repository
|
231
|
+
- Review the test files for usage examples
|
232
|
+
- Ensure all dependencies are installed correctly
|
233
|
+
- Verify your Python version is 3.12+
|
234
|
+
|
235
|
+
## Contributing
|
236
|
+
|
237
|
+
When contributing to `libinephany`:
|
238
|
+
|
239
|
+
1. Follow the existing code style (Black, isort, flake8)
|
240
|
+
2. Add appropriate type hints
|
241
|
+
3. Include unit tests for new functionality
|
242
|
+
4. Update documentation for new features
|
243
|
+
5. Ensure all tests pass before submitting
|
244
|
+
|
245
|
+
## License
|
246
|
+
|
247
|
+
This package is part of the Inephany ecosystem and is subject to the same licensing terms as other Inephany packages.
|
File without changes
|
File without changes
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# ======================================================================================================================
|
2
|
+
#
|
3
|
+
# IMPORTS
|
4
|
+
#
|
5
|
+
# ======================================================================================================================
|
6
|
+
|
7
|
+
import boto3
|
8
|
+
from loguru import logger
|
9
|
+
|
10
|
+
# ======================================================================================================================
|
11
|
+
#
|
12
|
+
# CONSTANTS
|
13
|
+
#
|
14
|
+
# ======================================================================================================================
|
15
|
+
|
16
|
+
S3_URI_SCHEME = "s3://"
|
17
|
+
S3_BUCKET_SEPARATOR = "/"
|
18
|
+
S3_BOTO_CLIENT = "s3"
|
19
|
+
|
20
|
+
# ======================================================================================================================
|
21
|
+
#
|
22
|
+
# FUNCTIONS
|
23
|
+
#
|
24
|
+
# ======================================================================================================================
|
25
|
+
|
26
|
+
|
27
|
+
def parse_s3_url(s3_url: str) -> tuple[str, str]:
|
28
|
+
"""
|
29
|
+
:param s3_url: S3 URL to parse and extract the bucket and blob names from.
|
30
|
+
:return: Tuple of:
|
31
|
+
- Bucket name.
|
32
|
+
- Blob name.
|
33
|
+
"""
|
34
|
+
|
35
|
+
if s3_url.startswith(S3_URI_SCHEME):
|
36
|
+
s3_url = s3_url.replace(S3_URI_SCHEME, "")
|
37
|
+
|
38
|
+
parts = s3_url.split(S3_BUCKET_SEPARATOR, 1)
|
39
|
+
bucket = parts[0]
|
40
|
+
key = parts[1] if len(parts) > 1 else ""
|
41
|
+
|
42
|
+
return bucket, key
|
43
|
+
|
44
|
+
|
45
|
+
def download_s3_file(s3_url: str, local_path: str) -> None:
|
46
|
+
"""
|
47
|
+
:param s3_url: S3 URL to download data from.
|
48
|
+
:param local_path: Path to save the contents of the download to.
|
49
|
+
"""
|
50
|
+
|
51
|
+
bucket, key = parse_s3_url(s3_url)
|
52
|
+
|
53
|
+
s3 = boto3.client(S3_BOTO_CLIENT)
|
54
|
+
|
55
|
+
logger.info(f"Downloading {s3_url} to {local_path}...")
|
56
|
+
s3.download_file(bucket, key, local_path)
|
57
|
+
logger.success("Done.")
|
File without changes
|