libinephany 1.1.22__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.
Files changed (72) hide show
  1. libinephany-1.1.22/CODE_VERSION.cfg +1 -0
  2. libinephany-1.1.22/LICENSE +180 -0
  3. libinephany-1.1.22/MANIFEST.in +7 -0
  4. libinephany-1.1.22/PKG-INFO +274 -0
  5. libinephany-1.1.22/README.md +230 -0
  6. libinephany-1.1.22/libinephany/__init__.py +0 -0
  7. libinephany-1.1.22/libinephany/aws/__init__.py +0 -0
  8. libinephany-1.1.22/libinephany/aws/s3_functions.py +57 -0
  9. libinephany-1.1.22/libinephany/observations/__init__.py +0 -0
  10. libinephany-1.1.22/libinephany/observations/observation_utils.py +516 -0
  11. libinephany-1.1.22/libinephany/observations/observer_pipeline.py +346 -0
  12. libinephany-1.1.22/libinephany/observations/observers/__init__.py +0 -0
  13. libinephany-1.1.22/libinephany/observations/observers/base_observers.py +519 -0
  14. libinephany-1.1.22/libinephany/observations/observers/global_observers/__init__.py +90 -0
  15. libinephany-1.1.22/libinephany/observations/observers/global_observers/base_classes.py +210 -0
  16. libinephany-1.1.22/libinephany/observations/observers/global_observers/constants.py +54 -0
  17. libinephany-1.1.22/libinephany/observations/observers/global_observers/gradient_observers.py +471 -0
  18. libinephany-1.1.22/libinephany/observations/observers/global_observers/hyperparameter_observers.py +423 -0
  19. libinephany-1.1.22/libinephany/observations/observers/global_observers/loss_observers.py +637 -0
  20. libinephany-1.1.22/libinephany/observations/observers/global_observers/model_observers.py +723 -0
  21. libinephany-1.1.22/libinephany/observations/observers/global_observers/progress_observers.py +239 -0
  22. libinephany-1.1.22/libinephany/observations/observers/local_observers.py +1250 -0
  23. libinephany-1.1.22/libinephany/observations/observers/observer_containers.py +293 -0
  24. libinephany-1.1.22/libinephany/observations/pipeline_coordinator.py +215 -0
  25. libinephany-1.1.22/libinephany/observations/post_processors/__init__.py +0 -0
  26. libinephany-1.1.22/libinephany/observations/post_processors/postprocessors.py +153 -0
  27. libinephany-1.1.22/libinephany/observations/statistic_manager.py +237 -0
  28. libinephany-1.1.22/libinephany/observations/statistic_trackers.py +1380 -0
  29. libinephany-1.1.22/libinephany/pydantic_models/__init__.py +0 -0
  30. libinephany-1.1.22/libinephany/pydantic_models/configs/__init__.py +0 -0
  31. libinephany-1.1.22/libinephany/pydantic_models/configs/hyperparameter_configs.py +464 -0
  32. libinephany-1.1.22/libinephany/pydantic_models/configs/observer_config.py +43 -0
  33. libinephany-1.1.22/libinephany/pydantic_models/configs/outer_model_config.py +27 -0
  34. libinephany-1.1.22/libinephany/pydantic_models/schemas/__init__.py +0 -0
  35. libinephany-1.1.22/libinephany/pydantic_models/schemas/agent_info.py +65 -0
  36. libinephany-1.1.22/libinephany/pydantic_models/schemas/inner_task_profile.py +310 -0
  37. libinephany-1.1.22/libinephany/pydantic_models/schemas/observation_models.py +68 -0
  38. libinephany-1.1.22/libinephany/pydantic_models/schemas/request_schemas.py +45 -0
  39. libinephany-1.1.22/libinephany/pydantic_models/schemas/response_schemas.py +68 -0
  40. libinephany-1.1.22/libinephany/pydantic_models/schemas/tensor_statistics.py +273 -0
  41. libinephany-1.1.22/libinephany/pydantic_models/states/__init__.py +0 -0
  42. libinephany-1.1.22/libinephany/pydantic_models/states/hyperparameter_states.py +915 -0
  43. libinephany-1.1.22/libinephany/utils/__init__.py +0 -0
  44. libinephany-1.1.22/libinephany/utils/adam_utils.py +19 -0
  45. libinephany-1.1.22/libinephany/utils/agent_utils.py +82 -0
  46. libinephany-1.1.22/libinephany/utils/asyncio_worker.py +87 -0
  47. libinephany-1.1.22/libinephany/utils/backend_statuses.py +20 -0
  48. libinephany-1.1.22/libinephany/utils/constants.py +91 -0
  49. libinephany-1.1.22/libinephany/utils/directory_utils.py +41 -0
  50. libinephany-1.1.22/libinephany/utils/dropout_utils.py +92 -0
  51. libinephany-1.1.22/libinephany/utils/enums.py +127 -0
  52. libinephany-1.1.22/libinephany/utils/error_severities.py +46 -0
  53. libinephany-1.1.22/libinephany/utils/exceptions.py +60 -0
  54. libinephany-1.1.22/libinephany/utils/import_utils.py +52 -0
  55. libinephany-1.1.22/libinephany/utils/optim_utils.py +239 -0
  56. libinephany-1.1.22/libinephany/utils/random_seeds.py +55 -0
  57. libinephany-1.1.22/libinephany/utils/samplers.py +535 -0
  58. libinephany-1.1.22/libinephany/utils/standardizers.py +217 -0
  59. libinephany-1.1.22/libinephany/utils/torch_distributed_utils.py +106 -0
  60. libinephany-1.1.22/libinephany/utils/torch_utils.py +77 -0
  61. libinephany-1.1.22/libinephany/utils/transforms.py +104 -0
  62. libinephany-1.1.22/libinephany/utils/typing.py +15 -0
  63. libinephany-1.1.22/libinephany/web_apps/__init__.py +0 -0
  64. libinephany-1.1.22/libinephany/web_apps/error_logger.py +451 -0
  65. libinephany-1.1.22/libinephany/web_apps/web_app_utils.py +123 -0
  66. libinephany-1.1.22/libinephany.egg-info/PKG-INFO +274 -0
  67. libinephany-1.1.22/libinephany.egg-info/SOURCES.txt +70 -0
  68. libinephany-1.1.22/libinephany.egg-info/dependency_links.txt +1 -0
  69. libinephany-1.1.22/libinephany.egg-info/requires.txt +27 -0
  70. libinephany-1.1.22/libinephany.egg-info/top_level.txt +1 -0
  71. libinephany-1.1.22/pyproject.toml +116 -0
  72. libinephany-1.1.22/setup.cfg +4 -0
@@ -0,0 +1 @@
1
+ 1.1.22
@@ -0,0 +1,180 @@
1
+ Copyright 2025 Inephany Ltd
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+
5
+ Apache License
6
+ Version 2.0, January 2004
7
+ http://www.apache.org/licenses/
8
+
9
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
10
+
11
+ 1. Definitions.
12
+
13
+ "License" shall mean the terms and conditions for use, reproduction,
14
+ and distribution as defined by Sections 1 through 9 of this document.
15
+
16
+ "Licensor" shall mean the copyright owner or entity authorized by
17
+ the copyright owner that is granting the License.
18
+
19
+ "Legal Entity" shall mean the union of the acting entity and all
20
+ other entities that control, are controlled by, or are under common
21
+ control with that entity. For the purposes of this definition,
22
+ "control" means (i) the power, direct or indirect, to cause the
23
+ direction or management of such entity, whether by contract or
24
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
25
+ outstanding shares, or (iii) beneficial ownership of such entity.
26
+
27
+ "You" (or "Your") shall mean an individual or Legal Entity
28
+ exercising permissions granted by this License.
29
+
30
+ "Source" form shall mean the preferred form for making modifications,
31
+ including but not limited to software source code, documentation
32
+ source, and configuration files.
33
+
34
+ "Object" form shall mean any form resulting from mechanical
35
+ transformation or translation of a Source form, including but
36
+ not limited to compiled object code, generated documentation,
37
+ and conversions to other media types.
38
+
39
+ "Work" shall mean the work of authorship, whether in Source or
40
+ Object form, made available under the License, as indicated by a
41
+ copyright notice that is included in or attached to the work
42
+ (an example is provided in the Appendix below).
43
+
44
+ "Derivative Works" shall mean any work, whether in Source or Object
45
+ form, that is based on (or derived from) the Work and for which the
46
+ editorial revisions, annotations, elaborations, or other modifications
47
+ represent, as a whole, an original work of authorship. For the purposes
48
+ of this License, Derivative Works shall not include works that remain
49
+ separable from, or merely link (or bind by name) to the interfaces of,
50
+ the Work and Derivative Works thereof.
51
+
52
+ "Contribution" shall mean any work of authorship, including
53
+ the original version of the Work and any modifications or additions
54
+ to that Work or Derivative Works thereof, that is intentionally
55
+ submitted to Licensor for inclusion in the Work by the copyright owner
56
+ or by an individual or Legal Entity authorized to submit on behalf of
57
+ the copyright owner. For the purposes of this definition, "submitted"
58
+ means any form of electronic, verbal, or written communication sent
59
+ to the Licensor or its representatives, including but not limited to
60
+ communication on electronic mailing lists, source code control systems,
61
+ and issue tracking systems that are managed by, or on behalf of, the
62
+ Licensor for the purpose of discussing and improving the Work, but
63
+ excluding communication that is conspicuously marked or otherwise
64
+ designated in writing by the copyright owner as "Not a Contribution."
65
+
66
+ "Contributor" shall mean Licensor and any individual or Legal Entity
67
+ on behalf of whom a Contribution has been received by Licensor and
68
+ subsequently incorporated within the Work.
69
+
70
+ 2. Grant of Copyright License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ copyright license to reproduce, prepare Derivative Works of,
74
+ publicly display, publicly perform, sublicense, and distribute the
75
+ Work and such Derivative Works in Source or Object form.
76
+
77
+ 3. Grant of Patent License. Subject to the terms and conditions of
78
+ this License, each Contributor hereby grants to You a perpetual,
79
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
80
+ (except as stated in this section) patent license to make, have made,
81
+ use, offer to sell, sell, import, and otherwise transfer the Work,
82
+ where such license applies only to those patent claims licensable
83
+ by such Contributor that are necessarily infringed by their
84
+ Contribution(s) alone or by combination of their Contribution(s)
85
+ with the Work to which such Contribution(s) was submitted. If You
86
+ institute patent litigation against any entity (including a
87
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
88
+ or a Contribution incorporated within the Work constitutes direct
89
+ or contributory patent infringement, then any patent licenses
90
+ granted to You under this License for that Work shall terminate
91
+ as of the date such litigation is filed.
92
+
93
+ 4. Redistribution. You may reproduce and distribute copies of the
94
+ Work or Derivative Works thereof in any medium, with or without
95
+ modifications, and in Source or Object form, provided that You
96
+ meet the following conditions:
97
+
98
+ (a) You must give any other recipients of the Work or
99
+ Derivative Works a copy of this License; and
100
+
101
+ (b) You must cause any modified files to carry prominent notices
102
+ stating that You changed the files; and
103
+
104
+ (c) You must retain, in the Source form of any Derivative Works
105
+ that You distribute, all copyright, patent, trademark, and
106
+ attribution notices from the Source form of the Work,
107
+ excluding those notices that do not pertain to any part of
108
+ the Derivative Works; and
109
+
110
+ (d) If the Work includes a "NOTICE" text file as part of its
111
+ distribution, then any Derivative Works that You distribute must
112
+ include a readable copy of the attribution notices contained
113
+ within such NOTICE file, excluding those notices that do not
114
+ pertain to any part of the Derivative Works, in at least one
115
+ of the following places: within a NOTICE text file distributed
116
+ as part of the Derivative Works; within the Source form or
117
+ documentation, if provided along with the Derivative Works; or,
118
+ within a display generated by the Derivative Works, if and
119
+ wherever such third-party notices normally appear. The contents
120
+ of the NOTICE file are for informational purposes only and
121
+ do not modify the License. You may add Your own attribution
122
+ notices within Derivative Works that You distribute, alongside
123
+ or as an addendum to the NOTICE text from the Work, provided
124
+ that such additional attribution notices cannot be construed
125
+ as modifying the License.
126
+
127
+ You may add Your own copyright statement to Your modifications and
128
+ may provide additional or different license terms and conditions
129
+ for use, reproduction, or distribution of Your modifications, or
130
+ for any such Derivative Works as a whole, provided Your use,
131
+ reproduction, and distribution of the Work otherwise complies with
132
+ the conditions stated in this License.
133
+
134
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
135
+ any Contribution intentionally submitted for inclusion in the Work
136
+ by You to the Licensor shall be under the terms and conditions of
137
+ this License, without any additional terms or conditions.
138
+ Notwithstanding the above, nothing herein shall supersede or modify
139
+ the terms of any separate license agreement you may have executed
140
+ with Licensor regarding such Contributions.
141
+
142
+ 6. Trademarks. This License does not grant permission to use the trade
143
+ names, trademarks, service marks, or product names of the Licensor,
144
+ except as required for reasonable and customary use in describing the
145
+ origin of the Work and reproducing the content of the NOTICE file.
146
+
147
+ 7. Disclaimer of Warranty. Unless required by applicable law or
148
+ agreed to in writing, Licensor provides the Work (and each
149
+ Contributor provides its Contributions) on an "AS IS" BASIS,
150
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
151
+ implied, including, without limitation, any warranties or conditions
152
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
153
+ PARTICULAR PURPOSE. You are solely responsible for determining the
154
+ appropriateness of using or redistributing the Work and assume any
155
+ risks associated with Your exercise of permissions under this License.
156
+
157
+ 8. Limitation of Liability. In no event and under no legal theory,
158
+ whether in tort (including negligence), contract, or otherwise,
159
+ unless required by applicable law (such as deliberate and grossly
160
+ negligent acts) or agreed to in writing, shall any Contributor be
161
+ liable to You for damages, including any direct, indirect, special,
162
+ incidental, or consequential damages of any character arising as a
163
+ result of this License or out of the use or inability to use the
164
+ Work (including but not limited to damages for loss of goodwill,
165
+ work stoppage, computer failure or malfunction, or any and all
166
+ other commercial damages or losses), even if such Contributor
167
+ has been advised of the possibility of such damages.
168
+
169
+ 9. Accepting Warranty or Additional Liability. While redistributing
170
+ the Work or Derivative Works thereof, You may choose to offer,
171
+ and charge a fee for, acceptance of support, warranty, indemnity,
172
+ or other liability obligations and/or rights consistent with this
173
+ License. However, in accepting such obligations, You may act only
174
+ on Your own behalf and on Your sole responsibility, not on behalf
175
+ of any other Contributor, and only if You agree to indemnify,
176
+ defend, and hold each Contributor harmless for any liability
177
+ incurred by, or claims asserted against, such Contributor by reason
178
+ of your accepting any such warranty or additional liability.
179
+
180
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,7 @@
1
+ include CODE_VERSION.cfg
2
+ include README.md
3
+ include LICENSE
4
+ include pyproject.toml
5
+ recursive-include libinephany *.py
6
+ recursive-exclude * __pycache__
7
+ recursive-exclude * *.py[co]
@@ -0,0 +1,274 @@
1
+ Metadata-Version: 2.4
2
+ Name: libinephany
3
+ Version: 1.1.22
4
+ Summary: Inephany library containing code commonly used by multiple subpackages.
5
+ Author-email: Inephany <info@inephany.com>
6
+ License: Apache 2.0
7
+ Keywords: libinephany,library,utilities
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: pydantic<3.0.0,>=2.5.0
18
+ Requires-Dist: loguru<0.8.0,>=0.7.0
19
+ Requires-Dist: requests<3.0.0,>=2.28.0
20
+ Requires-Dist: numpy<2.0.0,>=1.24.0
21
+ Requires-Dist: scipy<2.0.0,>=1.10.0
22
+ Requires-Dist: slack-sdk<4.0.0,>=3.20.0
23
+ Requires-Dist: boto3<2.0.0,>=1.26.0
24
+ Requires-Dist: fastapi<0.116.0,>=0.100.0
25
+ Requires-Dist: aiohttp<4.0.0,>=3.8.0
26
+ Requires-Dist: torch<2.9.0,>=2.1.0
27
+ Requires-Dist: transformers<4.48.3,>=4.30.0
28
+ Requires-Dist: pandas<3.0.0,>=2.0.0
29
+ Requires-Dist: accelerate<2.0.0,>=0.20.0
30
+ Requires-Dist: gymnasium<2.0.0,>=0.29.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest<9.0.0,>=7.0.0; extra == "dev"
33
+ Requires-Dist: pytest-mock<4.0.0,>=3.10.0; extra == "dev"
34
+ Requires-Dist: pytest-asyncio<0.26.0,>=0.21.0; extra == "dev"
35
+ Requires-Dist: bump-my-version==0.11.0; extra == "dev"
36
+ Requires-Dist: black==24.4.2; extra == "dev"
37
+ Requires-Dist: isort==5.9.3; extra == "dev"
38
+ Requires-Dist: flake8==7.1.0; extra == "dev"
39
+ Requires-Dist: pre-commit==4.0.1; extra == "dev"
40
+ Requires-Dist: mypy==1.13.0; extra == "dev"
41
+ Requires-Dist: types-PyYAML==6.0.12.20240808; extra == "dev"
42
+ Requires-Dist: typeguard==4.3.0; extra == "dev"
43
+ Dynamic: license-file
44
+
45
+ # Inephany Common Library
46
+
47
+ 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.
48
+
49
+ ## Features
50
+
51
+ - **Pydantic Data Models**: Comprehensive schemas for hyperparameters, observations, and API communications
52
+ - **Utility Functions**: Common utilities for PyTorch, optimization, transforms, and more
53
+ - **Observation System**: Tools for collecting and managing model statistics and observations
54
+ - **Constants and Enums**: Standardized constants and enumerations for agent types, model families, and module types
55
+ - **AWS Integration**: Utilities for AWS services integration
56
+ - **Web Application Utilities**: Common web app functionality and endpoints
57
+
58
+ ## Installation
59
+
60
+ ### Prerequisites
61
+
62
+ - Python 3.10+
63
+ - Make (for build automation)
64
+
65
+ #### Ubuntu / Debian
66
+ ```bash
67
+ sudo add-apt-repository ppa:deadsnakes/ppa
68
+ sudo apt update
69
+ sudo apt install python3.12
70
+ ```
71
+
72
+ #### MacOS with brew
73
+ ```bash
74
+ brew install python@3.12
75
+ ```
76
+
77
+ ### For Developers (Monorepo)
78
+
79
+ 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.
80
+
81
+ ### For Clients (Standalone Installation)
82
+
83
+ `libinephany` is available on PyPI and can be installed directly:
84
+
85
+ ```bash
86
+ pip install libinephany
87
+ ```
88
+
89
+ For development installations with additional dependencies:
90
+
91
+ ```bash
92
+ pip install libinephany[dev]
93
+ ```
94
+
95
+ ## Key Components
96
+
97
+ ### Pydantic Models
98
+
99
+ The package provides comprehensive data models for:
100
+
101
+ - **Hyperparameter Configurations**: `HParamConfig`, `HParamConfigs`
102
+ - **Observation Models**: `ObservationInputs`, tensor statistics
103
+ - **API Schemas**: Request/response models for client-server communication
104
+ - **State Management**: Hyperparameter states and update callbacks
105
+
106
+ ### Utility Functions
107
+
108
+ #### Agent Utilities (`agent_utils.py`)
109
+ - Agent ID generation and parsing
110
+ - Hyperparameter group management
111
+ - Agent type validation
112
+
113
+ #### Constants (`constants.py`)
114
+ - Hyperparameter type constants (learning_rate, weight_decay, etc.)
115
+ - Agent prefixes and suffixes
116
+ - API key headers and timestamp formats
117
+
118
+ #### Enums (`enums.py`)
119
+ - `AgentTypes`: Learning rate, weight decay, dropout, etc.
120
+ - `ModelFamilies`: GPT, BERT, OLMo
121
+ - `ModuleTypes`: Convolutional, attention, linear, embedding
122
+
123
+ #### Optimization Utilities (`optim_utils.py`)
124
+ - PyTorch optimizer utilities
125
+ - Parameter group management
126
+ - Learning rate scheduler utilities
127
+
128
+ #### PyTorch Utilities (`torch_utils.py`)
129
+ - Tensor operations
130
+ - Model utilities
131
+ - Distributed training helpers
132
+
133
+ ### Observation System
134
+
135
+ The observation system provides tools for collecting and managing model statistics:
136
+
137
+ - **StatisticManager**: Centralized statistics collection and management
138
+ - **ObserverPipeline**: Configurable observation pipelines
139
+ - **PipelineCoordinator**: Coordinates multiple observers
140
+ - **StatisticTrackers**: Specialized trackers for different metric types
141
+
142
+ ## Usage Examples
143
+
144
+ ### Basic Import Examples
145
+
146
+ ```python
147
+ # Import common constants
148
+ from libinephany.utils.constants import LEARNING_RATE, WEIGHT_DECAY, AGENT_PREFIX_LR
149
+
150
+ # Import enums
151
+ from libinephany.utils.enums import AgentTypes, ModelFamilies, ModuleTypes
152
+
153
+ # Import utility functions
154
+ from libinephany.utils import agent_utils, optim_utils, torch_utils
155
+
156
+ # Import data models
157
+ from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
158
+ from libinephany.pydantic_models.schemas.response_schemas import ClientPolicySchemaResponse
159
+ ```
160
+
161
+ ### Working with Agent Types
162
+
163
+ ```python
164
+ from libinephany.utils.enums import AgentTypes
165
+
166
+ # Check if an agent type is valid
167
+ agent_type = "learning_rate"
168
+ if agent_type in [agent.value for agent in AgentTypes]:
169
+ print(f"{agent_type} is a valid agent type")
170
+
171
+ # Get agent type by index
172
+ lr_agent = AgentTypes.get_from_index(0) # LearningRateAgent
173
+ ```
174
+
175
+ ### Using Constants
176
+
177
+ ```python
178
+ from libinephany.utils.constants import AGENT_PREFIX_LR, LEARNING_RATE
179
+
180
+ # Generate agent ID
181
+ agent_id = f"{AGENT_PREFIX_LR}_agent_001"
182
+ hyperparam_type = LEARNING_RATE
183
+ ```
184
+
185
+ ### Working with Pydantic Models
186
+
187
+ ```python
188
+ from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
189
+
190
+ # Create a hyperparameter configuration
191
+ config = HParamConfig(
192
+ name="learning_rate",
193
+ value=0.001,
194
+ min_value=1e-6,
195
+ max_value=1.0
196
+ )
197
+ ```
198
+
199
+ ## Development
200
+
201
+ ### Running Tests
202
+ ```bash
203
+ make execute-unit-tests
204
+ ```
205
+
206
+ ### Code Quality
207
+ ```bash
208
+ make lint # Run all linters
209
+ make fix-black # Fix formatting
210
+ make fix-isort # Fix imports
211
+ ```
212
+
213
+ ### Version Management
214
+ ```bash
215
+ make increment-patch-version # Increment patch version
216
+ make increment-minor-version # Increment minor version
217
+ make increment-major-version # Increment major version
218
+ make increment-pre-release-version # Increment pre-release version
219
+ ```
220
+
221
+ ## Dependencies
222
+
223
+ ### Core Dependencies
224
+ - `pydantic==2.8.2` - Data validation and serialization
225
+ - `torch==2.7.1` - PyTorch for tensor operations
226
+ - `numpy==1.26.4` - Numerical computing
227
+ - `requests==2.32.4` - HTTP client
228
+ - `loguru==0.7.2` - Logging
229
+
230
+ ### Optional Dependencies
231
+ - `boto3<=1.38.44` - AWS SDK
232
+ - `fastapi==0.115.11` - Web framework
233
+ - `slack-sdk==3.35.0` - Slack integration
234
+ - `transformers==4.52.4` - Hugging Face transformers
235
+ - `accelerate==1.4.0` - Hugging Face accelerate
236
+ - `gymnasium==1.0.0` - RL environments
237
+
238
+ ## Troubleshooting
239
+
240
+ ### Common Issues
241
+
242
+ 1. **Import Errors**: Ensure you're in the virtual environment and have installed the package correctly.
243
+
244
+ 2. **Version Conflicts**: If you encounter dependency conflicts, try installing in a fresh virtual environment:
245
+ ```bash
246
+ python -m venv fresh_env
247
+ source fresh_env/bin/activate
248
+ make install-dev
249
+ ```
250
+
251
+ 3. **Make Command Not Found**: Ensure you have `make` installed on your system.
252
+
253
+ 4. **Python Version Issues**: This package requires Python 3.12+. Ensure you're using the correct version.
254
+
255
+ ### Getting Help
256
+
257
+ - Check the example scripts in the repository
258
+ - Review the test files for usage examples
259
+ - Ensure all dependencies are installed correctly
260
+ - Verify your Python version is 3.12+
261
+
262
+ ## Contributing
263
+
264
+ When contributing to `libinephany`:
265
+
266
+ 1. Follow the existing code style (Black, isort, flake8)
267
+ 2. Add appropriate type hints
268
+ 3. Include unit tests for new functionality
269
+ 4. Update documentation for new features
270
+ 5. Ensure all tests pass before submitting
271
+
272
+ ## License
273
+
274
+ This package is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
@@ -0,0 +1,230 @@
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.10+
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
26
+ ```
27
+
28
+ #### MacOS with brew
29
+ ```bash
30
+ brew install python@3.12
31
+ ```
32
+
33
+ ### For Developers (Monorepo)
34
+
35
+ 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.
36
+
37
+ ### For Clients (Standalone Installation)
38
+
39
+ `libinephany` is available on PyPI and can be installed directly:
40
+
41
+ ```bash
42
+ pip install libinephany
43
+ ```
44
+
45
+ For development installations with additional dependencies:
46
+
47
+ ```bash
48
+ pip install libinephany[dev]
49
+ ```
50
+
51
+ ## Key Components
52
+
53
+ ### Pydantic Models
54
+
55
+ The package provides comprehensive data models for:
56
+
57
+ - **Hyperparameter Configurations**: `HParamConfig`, `HParamConfigs`
58
+ - **Observation Models**: `ObservationInputs`, tensor statistics
59
+ - **API Schemas**: Request/response models for client-server communication
60
+ - **State Management**: Hyperparameter states and update callbacks
61
+
62
+ ### Utility Functions
63
+
64
+ #### Agent Utilities (`agent_utils.py`)
65
+ - Agent ID generation and parsing
66
+ - Hyperparameter group management
67
+ - Agent type validation
68
+
69
+ #### Constants (`constants.py`)
70
+ - Hyperparameter type constants (learning_rate, weight_decay, etc.)
71
+ - Agent prefixes and suffixes
72
+ - API key headers and timestamp formats
73
+
74
+ #### Enums (`enums.py`)
75
+ - `AgentTypes`: Learning rate, weight decay, dropout, etc.
76
+ - `ModelFamilies`: GPT, BERT, OLMo
77
+ - `ModuleTypes`: Convolutional, attention, linear, embedding
78
+
79
+ #### Optimization Utilities (`optim_utils.py`)
80
+ - PyTorch optimizer utilities
81
+ - Parameter group management
82
+ - Learning rate scheduler utilities
83
+
84
+ #### PyTorch Utilities (`torch_utils.py`)
85
+ - Tensor operations
86
+ - Model utilities
87
+ - Distributed training helpers
88
+
89
+ ### Observation System
90
+
91
+ The observation system provides tools for collecting and managing model statistics:
92
+
93
+ - **StatisticManager**: Centralized statistics collection and management
94
+ - **ObserverPipeline**: Configurable observation pipelines
95
+ - **PipelineCoordinator**: Coordinates multiple observers
96
+ - **StatisticTrackers**: Specialized trackers for different metric types
97
+
98
+ ## Usage Examples
99
+
100
+ ### Basic Import Examples
101
+
102
+ ```python
103
+ # Import common constants
104
+ from libinephany.utils.constants import LEARNING_RATE, WEIGHT_DECAY, AGENT_PREFIX_LR
105
+
106
+ # Import enums
107
+ from libinephany.utils.enums import AgentTypes, ModelFamilies, ModuleTypes
108
+
109
+ # Import utility functions
110
+ from libinephany.utils import agent_utils, optim_utils, torch_utils
111
+
112
+ # Import data models
113
+ from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
114
+ from libinephany.pydantic_models.schemas.response_schemas import ClientPolicySchemaResponse
115
+ ```
116
+
117
+ ### Working with Agent Types
118
+
119
+ ```python
120
+ from libinephany.utils.enums import AgentTypes
121
+
122
+ # Check if an agent type is valid
123
+ agent_type = "learning_rate"
124
+ if agent_type in [agent.value for agent in AgentTypes]:
125
+ print(f"{agent_type} is a valid agent type")
126
+
127
+ # Get agent type by index
128
+ lr_agent = AgentTypes.get_from_index(0) # LearningRateAgent
129
+ ```
130
+
131
+ ### Using Constants
132
+
133
+ ```python
134
+ from libinephany.utils.constants import AGENT_PREFIX_LR, LEARNING_RATE
135
+
136
+ # Generate agent ID
137
+ agent_id = f"{AGENT_PREFIX_LR}_agent_001"
138
+ hyperparam_type = LEARNING_RATE
139
+ ```
140
+
141
+ ### Working with Pydantic Models
142
+
143
+ ```python
144
+ from libinephany.pydantic_models.configs.hyperparameter_configs import HParamConfig
145
+
146
+ # Create a hyperparameter configuration
147
+ config = HParamConfig(
148
+ name="learning_rate",
149
+ value=0.001,
150
+ min_value=1e-6,
151
+ max_value=1.0
152
+ )
153
+ ```
154
+
155
+ ## Development
156
+
157
+ ### Running Tests
158
+ ```bash
159
+ make execute-unit-tests
160
+ ```
161
+
162
+ ### Code Quality
163
+ ```bash
164
+ make lint # Run all linters
165
+ make fix-black # Fix formatting
166
+ make fix-isort # Fix imports
167
+ ```
168
+
169
+ ### Version Management
170
+ ```bash
171
+ make increment-patch-version # Increment patch version
172
+ make increment-minor-version # Increment minor version
173
+ make increment-major-version # Increment major version
174
+ make increment-pre-release-version # Increment pre-release version
175
+ ```
176
+
177
+ ## Dependencies
178
+
179
+ ### Core Dependencies
180
+ - `pydantic==2.8.2` - Data validation and serialization
181
+ - `torch==2.7.1` - PyTorch for tensor operations
182
+ - `numpy==1.26.4` - Numerical computing
183
+ - `requests==2.32.4` - HTTP client
184
+ - `loguru==0.7.2` - Logging
185
+
186
+ ### Optional Dependencies
187
+ - `boto3<=1.38.44` - AWS SDK
188
+ - `fastapi==0.115.11` - Web framework
189
+ - `slack-sdk==3.35.0` - Slack integration
190
+ - `transformers==4.52.4` - Hugging Face transformers
191
+ - `accelerate==1.4.0` - Hugging Face accelerate
192
+ - `gymnasium==1.0.0` - RL environments
193
+
194
+ ## Troubleshooting
195
+
196
+ ### Common Issues
197
+
198
+ 1. **Import Errors**: Ensure you're in the virtual environment and have installed the package correctly.
199
+
200
+ 2. **Version Conflicts**: If you encounter dependency conflicts, try installing in a fresh virtual environment:
201
+ ```bash
202
+ python -m venv fresh_env
203
+ source fresh_env/bin/activate
204
+ make install-dev
205
+ ```
206
+
207
+ 3. **Make Command Not Found**: Ensure you have `make` installed on your system.
208
+
209
+ 4. **Python Version Issues**: This package requires Python 3.12+. Ensure you're using the correct version.
210
+
211
+ ### Getting Help
212
+
213
+ - Check the example scripts in the repository
214
+ - Review the test files for usage examples
215
+ - Ensure all dependencies are installed correctly
216
+ - Verify your Python version is 3.12+
217
+
218
+ ## Contributing
219
+
220
+ When contributing to `libinephany`:
221
+
222
+ 1. Follow the existing code style (Black, isort, flake8)
223
+ 2. Add appropriate type hints
224
+ 3. Include unit tests for new functionality
225
+ 4. Update documentation for new features
226
+ 5. Ensure all tests pass before submitting
227
+
228
+ ## License
229
+
230
+ This package is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
File without changes
File without changes