silver-adapters 0.1.0__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.
- silver_adapters-0.1.0/CHANGELOG.md +33 -0
- silver_adapters-0.1.0/CONTRIBUTING.md +140 -0
- silver_adapters-0.1.0/LICENSE +12 -0
- silver_adapters-0.1.0/MANIFEST.in +6 -0
- silver_adapters-0.1.0/PKG-INFO +404 -0
- silver_adapters-0.1.0/README.md +350 -0
- silver_adapters-0.1.0/pyproject.toml +63 -0
- silver_adapters-0.1.0/setup.cfg +4 -0
- silver_adapters-0.1.0/src/silver_adapters/__init__.py +31 -0
- silver_adapters-0.1.0/src/silver_adapters/frameworks.py +72 -0
- silver_adapters-0.1.0/src/silver_adapters/models.py +50 -0
- silver_adapters-0.1.0/src/silver_adapters/notebooks.py +57 -0
- silver_adapters-0.1.0/src/silver_adapters/protocols.py +54 -0
- silver_adapters-0.1.0/src/silver_adapters/remote.py +57 -0
- silver_adapters-0.1.0/src/silver_adapters.egg-info/PKG-INFO +404 -0
- silver_adapters-0.1.0/src/silver_adapters.egg-info/SOURCES.txt +19 -0
- silver_adapters-0.1.0/src/silver_adapters.egg-info/dependency_links.txt +1 -0
- silver_adapters-0.1.0/src/silver_adapters.egg-info/requires.txt +39 -0
- silver_adapters-0.1.0/src/silver_adapters.egg-info/top_level.txt +1 -0
- silver_adapters-0.1.0/tests/__init__.py +1 -0
- silver_adapters-0.1.0/tests/test_adapters.py +352 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2024-08-04
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of silver-adapters
|
|
12
|
+
- PyTorch bridge utilities for checkpoint management
|
|
13
|
+
- TensorFlow/Keras bridge utilities for model saving/loading
|
|
14
|
+
- JSONL protocol encoding and decoding for event streaming
|
|
15
|
+
- Remote training client with async HTTP support
|
|
16
|
+
- Jupyter notebook template generation
|
|
17
|
+
- Data import plans for pandas and Kaggle
|
|
18
|
+
- Framework command bridge creation
|
|
19
|
+
- Comprehensive test suite with mocking for optional dependencies
|
|
20
|
+
- Support for Python 3.8-3.12
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
- `PyTorchBridge` - PyTorch checkpoint utilities
|
|
24
|
+
- `TensorFlowBridge` - TensorFlow/Keras model utilities
|
|
25
|
+
- `RemoteTrainingClient` - HTTP client for remote training
|
|
26
|
+
- `encode_jsonl()` / `decode_jsonl()` - JSONL protocol handling
|
|
27
|
+
- `notebook_document()` / `silver_notebook_cells()` - Jupyter utilities
|
|
28
|
+
- `python_framework()` - Framework command bridge creation
|
|
29
|
+
- `pandas_import()` / `kaggle_import()` - Data import planning
|
|
30
|
+
- Optional dependencies for specific framework support
|
|
31
|
+
- Async HTTP operations for remote training
|
|
32
|
+
|
|
33
|
+
## [Unreleased]
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Contributing to silver-adapters
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to silver-adapters! This document provides guidelines and instructions for contributing to the project.
|
|
4
|
+
|
|
5
|
+
## Development Setup
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
- Python 3.8 or higher
|
|
9
|
+
- Git
|
|
10
|
+
- Virtual environment (recommended)
|
|
11
|
+
|
|
12
|
+
### Setting Up Development Environment
|
|
13
|
+
|
|
14
|
+
1. **Clone the repository**
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/adfgdartec/silver-adapters.git
|
|
17
|
+
cd silver-adapters
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. **Create a virtual environment**
|
|
21
|
+
```bash
|
|
22
|
+
python -m venv venv
|
|
23
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
3. **Install development dependencies**
|
|
27
|
+
```bash
|
|
28
|
+
pip install -e ".[dev]"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
4. **Install optional dependencies for testing**
|
|
32
|
+
```bash
|
|
33
|
+
pip install -e ".[all]" # Or specific: [pytorch], [tensorflow], etc.
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
5. **Run tests**
|
|
37
|
+
```bash
|
|
38
|
+
pytest
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
6. **Run tests with coverage**
|
|
42
|
+
```bash
|
|
43
|
+
pytest --cov=silver_adapters --cov-report=html
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Code Style
|
|
47
|
+
|
|
48
|
+
We use the following tools to maintain code quality:
|
|
49
|
+
|
|
50
|
+
- **flake8** for linting
|
|
51
|
+
- **mypy** for type checking
|
|
52
|
+
- **pytest** for testing
|
|
53
|
+
|
|
54
|
+
Run all quality checks:
|
|
55
|
+
```bash
|
|
56
|
+
flake8 src/ tests/
|
|
57
|
+
mypy src/
|
|
58
|
+
pytest
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Making Changes
|
|
62
|
+
|
|
63
|
+
1. **Create a branch**
|
|
64
|
+
```bash
|
|
65
|
+
git checkout -b feature/your-feature-name
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
2. **Make your changes**
|
|
69
|
+
- Write clear, descriptive commit messages
|
|
70
|
+
- Add tests for new functionality
|
|
71
|
+
- Update documentation as needed
|
|
72
|
+
- Handle optional dependencies gracefully
|
|
73
|
+
|
|
74
|
+
3. **Run tests**
|
|
75
|
+
```bash
|
|
76
|
+
pytest
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
4. **Submit a pull request**
|
|
80
|
+
- Describe your changes clearly
|
|
81
|
+
- Reference any related issues
|
|
82
|
+
- Ensure all tests pass
|
|
83
|
+
- Note any optional dependencies required
|
|
84
|
+
|
|
85
|
+
## Testing
|
|
86
|
+
|
|
87
|
+
We aim for high test coverage. When adding new features:
|
|
88
|
+
|
|
89
|
+
- Write unit tests for new adapter functions
|
|
90
|
+
- Mock optional dependencies (torch, tensorflow, etc.)
|
|
91
|
+
- Test error handling for missing dependencies
|
|
92
|
+
- Ensure existing tests still pass
|
|
93
|
+
|
|
94
|
+
### Test Structure
|
|
95
|
+
```
|
|
96
|
+
tests/
|
|
97
|
+
├── __init__.py
|
|
98
|
+
└── test_adapters.py
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Optional Dependencies
|
|
102
|
+
|
|
103
|
+
This package has optional dependencies for different ML frameworks:
|
|
104
|
+
|
|
105
|
+
- `pytorch` - PyTorch support
|
|
106
|
+
- `tensorflow` - TensorFlow support
|
|
107
|
+
- `keras` - Keras support
|
|
108
|
+
- `kaggle` - Kaggle API support
|
|
109
|
+
- `jupyter` - Jupyter notebook support
|
|
110
|
+
|
|
111
|
+
When adding new framework-specific features:
|
|
112
|
+
|
|
113
|
+
1. Add the dependency to `pyproject.toml` under `project.optional-dependencies`
|
|
114
|
+
2. Import the dependency inside the function (not at module level)
|
|
115
|
+
3. Provide clear error messages when the dependency is missing
|
|
116
|
+
4. Add tests that mock the dependency
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
120
|
+
- Update docstrings for any modified functions
|
|
121
|
+
- Add examples for new adapters
|
|
122
|
+
- Update README.md if user-facing changes are made
|
|
123
|
+
- Document any new optional dependencies
|
|
124
|
+
|
|
125
|
+
## Release Process
|
|
126
|
+
|
|
127
|
+
Releases are managed by maintainers:
|
|
128
|
+
|
|
129
|
+
1. Update version in `pyproject.toml`
|
|
130
|
+
2. Update `CHANGELOG.md`
|
|
131
|
+
3. Create a GitHub release
|
|
132
|
+
4. Package will be automatically published to PyPI
|
|
133
|
+
|
|
134
|
+
## Questions?
|
|
135
|
+
|
|
136
|
+
Feel free to open an issue for questions or discussions about contributions.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
By contributing, you agree that your contributions will be licensed under the Apache-2.0 License.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
|
|
4
|
+
Copyright 2026 Silver Contributors
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0. You may obtain a copy of the
|
|
7
|
+
License at https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
10
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
11
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
12
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: silver-adapters
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Backend, dataset, notebook, and remote-training bridge protocols for Silver.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/adfgdartec/silver-adapters
|
|
7
|
+
Project-URL: Repository, https://github.com/adfgdartec/silver-adapters
|
|
8
|
+
Project-URL: Issues, https://github.com/adfgdartec/silver-adapters/issues
|
|
9
|
+
Keywords: pytorch,keras,tensorflow,pandas,kaggle,jupyter,machine-learning,python
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Provides-Extra: pytorch
|
|
24
|
+
Requires-Dist: torch>=1.9.0; extra == "pytorch"
|
|
25
|
+
Provides-Extra: tensorflow
|
|
26
|
+
Requires-Dist: tensorflow>=2.6.0; extra == "tensorflow"
|
|
27
|
+
Provides-Extra: keras
|
|
28
|
+
Requires-Dist: tensorflow>=2.6.0; extra == "keras"
|
|
29
|
+
Provides-Extra: kaggle
|
|
30
|
+
Requires-Dist: kaggle>=1.5.0; extra == "kaggle"
|
|
31
|
+
Provides-Extra: jupyter
|
|
32
|
+
Requires-Dist: jupyter>=1.0.0; extra == "jupyter"
|
|
33
|
+
Requires-Dist: nbformat>=5.0.0; extra == "jupyter"
|
|
34
|
+
Provides-Extra: pandas
|
|
35
|
+
Requires-Dist: pandas>=1.0.0; extra == "pandas"
|
|
36
|
+
Provides-Extra: remote
|
|
37
|
+
Requires-Dist: requests>=2.25.0; extra == "remote"
|
|
38
|
+
Provides-Extra: all
|
|
39
|
+
Requires-Dist: torch>=1.9.0; extra == "all"
|
|
40
|
+
Requires-Dist: tensorflow>=2.6.0; extra == "all"
|
|
41
|
+
Requires-Dist: kaggle>=1.5.0; extra == "all"
|
|
42
|
+
Requires-Dist: jupyter>=1.0.0; extra == "all"
|
|
43
|
+
Requires-Dist: nbformat>=5.0.0; extra == "all"
|
|
44
|
+
Requires-Dist: pandas>=1.0.0; extra == "all"
|
|
45
|
+
Requires-Dist: requests>=2.25.0; extra == "all"
|
|
46
|
+
Provides-Extra: dev
|
|
47
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
48
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
49
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
50
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
51
|
+
Requires-Dist: build>=0.10.0; extra == "dev"
|
|
52
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
53
|
+
Dynamic: license-file
|
|
54
|
+
|
|
55
|
+
# silver-adapters
|
|
56
|
+
|
|
57
|
+
[](https://www.python.org/downloads/)
|
|
58
|
+
[](LICENSE)
|
|
59
|
+
[](tests/)
|
|
60
|
+
[](https://flake8.pycqa.org/)
|
|
61
|
+
|
|
62
|
+
Backend, dataset, notebook, and remote-training bridge protocols for Silver. A Python package designed for ML researchers who need seamless integration between different ML frameworks and tools.
|
|
63
|
+
|
|
64
|
+
The core package has no mandatory ML framework, pandas, requests, or Jupyter
|
|
65
|
+
dependency. Install only the extras you need:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install silver-adapters
|
|
69
|
+
pip install 'silver-adapters[pytorch]'
|
|
70
|
+
pip install 'silver-adapters[remote]'
|
|
71
|
+
pip install 'silver-adapters[pandas]'
|
|
72
|
+
pip install 'silver-adapters[jupyter]'
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Installation
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Core package
|
|
79
|
+
pip install silver-adapters
|
|
80
|
+
|
|
81
|
+
# With specific framework support
|
|
82
|
+
pip install silver-adapters[pytorch]
|
|
83
|
+
pip install silver-adapters[tensorflow]
|
|
84
|
+
pip install silver-adapters[kaggle]
|
|
85
|
+
pip install silver-adapters[jupyter]
|
|
86
|
+
|
|
87
|
+
# With all optional dependencies
|
|
88
|
+
pip install silver-adapters[all]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Quick Start
|
|
92
|
+
|
|
93
|
+
### Framework Bridges
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from silver_adapters import python_framework, PyTorchBridge, TensorFlowBridge
|
|
97
|
+
|
|
98
|
+
# Create a PyTorch training bridge
|
|
99
|
+
bridge = python_framework(
|
|
100
|
+
framework="pytorch",
|
|
101
|
+
script="train.py",
|
|
102
|
+
args=["--config", "config.yaml"]
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# PyTorch checkpoint utilities
|
|
106
|
+
checkpoint = PyTorchBridge.from_checkpoint("model.pt")
|
|
107
|
+
PyTorchBridge.to_checkpoint(model, optimizer, epoch=10, path="model.pt")
|
|
108
|
+
|
|
109
|
+
# TensorFlow/Keras checkpoint utilities
|
|
110
|
+
model = TensorFlowBridge.from_checkpoint("model.h5")
|
|
111
|
+
TensorFlowBridge.to_checkpoint(model, "model.h5")
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Data Import
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from silver_adapters import pandas_import, kaggle_import
|
|
118
|
+
|
|
119
|
+
# Import from pandas
|
|
120
|
+
plan = pandas_import("data/train.csv")
|
|
121
|
+
|
|
122
|
+
# Import from Kaggle
|
|
123
|
+
plan = kaggle_import("competiton/dataset-name")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Remote Training
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
import asyncio
|
|
130
|
+
from silver_adapters import RemoteTrainingClient
|
|
131
|
+
|
|
132
|
+
async def main():
|
|
133
|
+
client = RemoteTrainingClient("https://api.example.com")
|
|
134
|
+
|
|
135
|
+
# Start training
|
|
136
|
+
run = await client.start({"config": {...}})
|
|
137
|
+
|
|
138
|
+
# Get events
|
|
139
|
+
events = await client.events(run["run_id"])
|
|
140
|
+
|
|
141
|
+
# Stop training
|
|
142
|
+
await client.stop(run["run_id"], "completed successfully")
|
|
143
|
+
|
|
144
|
+
asyncio.run(main())
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### JSONL Protocol
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from silver_adapters import encode_jsonl, decode_jsonl, SilverJsonlEvent
|
|
151
|
+
|
|
152
|
+
# Encode events
|
|
153
|
+
events = [
|
|
154
|
+
SilverJsonlEvent(kind="epoch", data={"epoch": 1, "loss": 0.5}),
|
|
155
|
+
SilverJsonlEvent(kind="metrics", data={"accuracy": 0.9})
|
|
156
|
+
]
|
|
157
|
+
jsonl = encode_jsonl(events)
|
|
158
|
+
|
|
159
|
+
# Decode events
|
|
160
|
+
decoded = decode_jsonl(jsonl)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Features
|
|
164
|
+
|
|
165
|
+
- **Framework Bridges**: Seamless integration with PyTorch, TensorFlow, and Keras
|
|
166
|
+
- **Data Import Plans**: Structured data import from pandas and Kaggle
|
|
167
|
+
- **Remote Training**: Async HTTP client for distributed training
|
|
168
|
+
- **JSONL Protocol**: Event streaming protocol for training observability
|
|
169
|
+
- **Jupyter Integration**: Notebook utilities and template generation
|
|
170
|
+
- **Checkpoint Management**: Unified checkpoint handling across frameworks
|
|
171
|
+
- **Type Safety**: Full type hints for better IDE support and fewer bugs
|
|
172
|
+
|
|
173
|
+
## Use Cases
|
|
174
|
+
|
|
175
|
+
### Multi-Framework Training
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from silver_adapters import PyTorchBridge, TensorFlowBridge
|
|
179
|
+
import torch
|
|
180
|
+
import tensorflow as tf
|
|
181
|
+
|
|
182
|
+
# Train in PyTorch
|
|
183
|
+
pytorch_model = torch.nn.Linear(10, 2)
|
|
184
|
+
optimizer = torch.optim.Adam(pytorch_model.parameters())
|
|
185
|
+
|
|
186
|
+
# Save PyTorch checkpoint
|
|
187
|
+
PyTorchBridge.to_checkpoint(pytorch_model, optimizer, epoch=10, path="pytorch_model.pt")
|
|
188
|
+
|
|
189
|
+
# Load in TensorFlow for inference
|
|
190
|
+
tf_model = tf.keras.Sequential([tf.keras.layers.Dense(2, input_shape=(10,))])
|
|
191
|
+
# Convert weights (framework-specific conversion needed)
|
|
192
|
+
TensorFlowBridge.to_checkpoint(tf_model, "tf_model.h5")
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Distributed Training Setup
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
import asyncio
|
|
199
|
+
from silver_adapters import RemoteTrainingClient
|
|
200
|
+
|
|
201
|
+
async def run_distributed_training():
|
|
202
|
+
# Connect to remote training server
|
|
203
|
+
client = RemoteTrainingClient("https://training-server.example.com")
|
|
204
|
+
|
|
205
|
+
# Start training on remote GPU cluster
|
|
206
|
+
config = {
|
|
207
|
+
"model": "resnet50",
|
|
208
|
+
"dataset": "imagenet",
|
|
209
|
+
"batch_size": 32,
|
|
210
|
+
"epochs": 100
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
run = await client.start(config)
|
|
214
|
+
print(f"Started training run: {run['run_id']}")
|
|
215
|
+
|
|
216
|
+
# Monitor training progress
|
|
217
|
+
while True:
|
|
218
|
+
events = await client.events(run['run_id'])
|
|
219
|
+
latest_events = events[-5:] # Get last 5 events
|
|
220
|
+
|
|
221
|
+
for event in latest_events:
|
|
222
|
+
if event['kind'] == 'epoch':
|
|
223
|
+
print(f"Epoch {event['epoch']}: loss={event.get('loss', 'N/A')}")
|
|
224
|
+
elif event['kind'] == 'completed':
|
|
225
|
+
print("Training completed!")
|
|
226
|
+
return
|
|
227
|
+
|
|
228
|
+
await asyncio.sleep(10) # Check every 10 seconds
|
|
229
|
+
|
|
230
|
+
asyncio.run(run_distributed_training())
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Data Pipeline Integration
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
from silver_adapters import pandas_import, kaggle_import, encode_jsonl
|
|
237
|
+
import pandas as pd
|
|
238
|
+
|
|
239
|
+
# Create data import plans
|
|
240
|
+
csv_plan = pandas_import("data/train.csv", {"sep": ",", "encoding": "utf-8"})
|
|
241
|
+
kaggle_plan = kaggle_import("competiton/titanic", {"unzip": True})
|
|
242
|
+
|
|
243
|
+
# Use plans in your data pipeline
|
|
244
|
+
def execute_import_plan(plan):
|
|
245
|
+
"""Execute a data import plan"""
|
|
246
|
+
if plan.source == "pandas":
|
|
247
|
+
df = pd.read_csv(plan.args[1], **plan.options)
|
|
248
|
+
return df
|
|
249
|
+
elif plan.source == "kaggle":
|
|
250
|
+
# Execute Kaggle download command
|
|
251
|
+
import subprocess
|
|
252
|
+
subprocess.run([plan.command] + plan.args)
|
|
253
|
+
return pd.read_csv("downloaded_file.csv")
|
|
254
|
+
|
|
255
|
+
# Create training events from pandas DataFrame
|
|
256
|
+
def create_training_events(df):
|
|
257
|
+
from silver_adapters import SilverJsonlEvent
|
|
258
|
+
events = []
|
|
259
|
+
|
|
260
|
+
for epoch in range(10):
|
|
261
|
+
# Simulate training metrics
|
|
262
|
+
events.append(SilverJsonlEvent(
|
|
263
|
+
kind="epoch",
|
|
264
|
+
data={"epoch": epoch, "loss": 0.5 - epoch * 0.05}
|
|
265
|
+
))
|
|
266
|
+
|
|
267
|
+
return encode_jsonl(events)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Jupyter Notebook Integration
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
from silver_adapters import notebook_document, silver_notebook_cells
|
|
274
|
+
|
|
275
|
+
# Create a Silver training notebook
|
|
276
|
+
cells = silver_notebook_cells()
|
|
277
|
+
notebook = notebook_document(cells)
|
|
278
|
+
|
|
279
|
+
# Save as Jupyter notebook
|
|
280
|
+
import json
|
|
281
|
+
with open("silver_training.ipynb", "w") as f:
|
|
282
|
+
json.dump({
|
|
283
|
+
"cells": [
|
|
284
|
+
{
|
|
285
|
+
"cell_type": cell.cell_type,
|
|
286
|
+
"metadata": cell.metadata,
|
|
287
|
+
"source": cell.source,
|
|
288
|
+
"outputs": cell.outputs or [],
|
|
289
|
+
"execution_count": cell.execution_count
|
|
290
|
+
} for cell in notebook.cells
|
|
291
|
+
],
|
|
292
|
+
"metadata": notebook.metadata,
|
|
293
|
+
"nbformat": notebook.nbformat,
|
|
294
|
+
"nbformat_minor": notebook.nbformat_minor
|
|
295
|
+
}, f, indent=2)
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Advanced Usage
|
|
299
|
+
|
|
300
|
+
### Custom Training Backend
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
from silver_adapters import python_framework, PythonFramework
|
|
304
|
+
import subprocess
|
|
305
|
+
|
|
306
|
+
class CustomTrainingBackend:
|
|
307
|
+
def __init__(self, framework, script_path):
|
|
308
|
+
self.bridge = python_framework(
|
|
309
|
+
framework=framework,
|
|
310
|
+
script=script_path,
|
|
311
|
+
environment={"CUDA_VISIBLE_DEVICES": "0"}
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
def launch_training(self, args):
|
|
315
|
+
"""Launch training with given arguments"""
|
|
316
|
+
cmd = [self.bridge.command] + self.bridge.args + args
|
|
317
|
+
env = {**self.bridge.environment}
|
|
318
|
+
|
|
319
|
+
process = subprocess.Popen(
|
|
320
|
+
cmd,
|
|
321
|
+
env={**subprocess.os.environ, **env}
|
|
322
|
+
)
|
|
323
|
+
return process
|
|
324
|
+
|
|
325
|
+
# Usage
|
|
326
|
+
backend = CustomTrainingBackend(
|
|
327
|
+
PythonFramework.PYTORCH,
|
|
328
|
+
"train.py"
|
|
329
|
+
)
|
|
330
|
+
process = backend.launch_training(["--epochs", "100", "--batch-size", "32"])
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Event Streaming
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
from silver_adapters import encode_jsonl, decode_jsonl, SilverJsonlEvent
|
|
337
|
+
import asyncio
|
|
338
|
+
|
|
339
|
+
async def stream_training_events(writer):
|
|
340
|
+
"""Stream training events to a writer"""
|
|
341
|
+
for epoch in range(10):
|
|
342
|
+
event = SilverJsonlEvent(
|
|
343
|
+
kind="epoch",
|
|
344
|
+
data={"epoch": epoch, "loss": 0.5 - epoch * 0.05}
|
|
345
|
+
)
|
|
346
|
+
writer.write(encode_jsonl([event]))
|
|
347
|
+
await asyncio.sleep(0.1)
|
|
348
|
+
|
|
349
|
+
async def consume_training_events(reader):
|
|
350
|
+
"""Consume training events from a reader"""
|
|
351
|
+
buffer = ""
|
|
352
|
+
async for chunk in reader:
|
|
353
|
+
buffer += chunk
|
|
354
|
+
events = decode_jsonl(buffer)
|
|
355
|
+
for event in events:
|
|
356
|
+
print(f"Received: {event.kind} - {event.data}")
|
|
357
|
+
buffer = ""
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Requirements
|
|
361
|
+
|
|
362
|
+
- Python 3.8+
|
|
363
|
+
- pandas>=1.0.0
|
|
364
|
+
- requests>=2.25.0
|
|
365
|
+
|
|
366
|
+
### Optional Dependencies
|
|
367
|
+
- torch>=1.9.0 (for PyTorch support)
|
|
368
|
+
- tensorflow>=2.6.0 (for TensorFlow/Keras support)
|
|
369
|
+
- kaggle>=1.5.0 (for Kaggle integration)
|
|
370
|
+
- jupyter>=1.0.0 (for notebook utilities)
|
|
371
|
+
|
|
372
|
+
## Development
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
# Install development dependencies
|
|
376
|
+
pip install -e ".[dev]"
|
|
377
|
+
|
|
378
|
+
# Install all optional dependencies for testing
|
|
379
|
+
pip install -e ".[all]"
|
|
380
|
+
|
|
381
|
+
# Run tests
|
|
382
|
+
pytest
|
|
383
|
+
|
|
384
|
+
# Run tests with coverage
|
|
385
|
+
pytest --cov=silver_adapters --cov-report=html
|
|
386
|
+
|
|
387
|
+
# Run linting
|
|
388
|
+
flake8 src/ tests/
|
|
389
|
+
mypy src/
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Contributing
|
|
393
|
+
|
|
394
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
395
|
+
|
|
396
|
+
## License
|
|
397
|
+
|
|
398
|
+
Apache-2.0 - see [LICENSE](LICENSE) file for details.
|
|
399
|
+
|
|
400
|
+
## Related Packages
|
|
401
|
+
|
|
402
|
+
- [silver-data](https://github.com/adfgdartec/silver-data) - Dataset handling
|
|
403
|
+
- [silver-run](https://github.com/adfgdartec/silver-run) - Training lifecycle
|
|
404
|
+
- [silver-diagnostics](https://github.com/adfgdartec/silver-diagnostics) - ML diagnostics
|