File size: 9,447 Bytes
5fe83da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# Trackio Deployment Guide for Hugging Face Spaces

This guide provides step-by-step instructions for deploying Trackio experiment tracking to Hugging Face Spaces and integrating it with your SmolLM3 fine-tuning pipeline.

## Prerequisites

- Hugging Face account
- Hugging Face CLI installed (`pip install huggingface_hub`)
- Git configured with your Hugging Face credentials

## Method 1: Automated Deployment (Recommended)

### Step 1: Run the Deployment Script

```bash
python deploy_trackio_space.py
```

The script will prompt you for:
- Your Hugging Face username
- Space name (e.g., `trackio-monitoring`)
- Hugging Face token (needs a write token obviously)

### Step 2: Wait for Build

After deployment, wait 2-5 minutes for the Space to build and become available.

### Step 3: Test the Interface

Visit your Space URL to test the interface:
```
https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
```

## Method 2: Manual Deployment

### Step 1: Create a New Space

1. Go to https://huggingface.co/spaces
2. Click "Create new Space"
3. Configure the Space:
   - **Owner**: Your username
   - **Space name**: `trackio-monitoring` (or your preferred name)
   - **SDK**: Gradio
   - **Hardware**: CPU (Basic)
   - **License**: MIT

### Step 2: Upload Files

Upload these files to your Space:

#### `app.py`
The main Gradio interface (already created in this repository)

#### `requirements_space.txt`
```
gradio>=4.0.0
gradio-client>=0.10.0
requests>=2.31.0
numpy>=1.24.0
pandas>=2.0.0
jsonschema>=4.17.0
plotly>=5.15.0
matplotlib>=3.7.0
python-dotenv>=1.0.0
```

#### `README.md`
```markdown
# Trackio Experiment Tracking

A Gradio interface for experiment tracking and monitoring.

## Features

- Create and manage experiments
- Log training metrics and parameters
- View experiment details and results
- Update experiment status

## Usage

1. Create a new experiment using the "Create Experiment" tab
2. Log metrics during training using the "Log Metrics" tab
3. View experiment details using the "View Experiments" tab
4. Update experiment status using the "Update Status" tab

## Integration

To connect your training script to this Trackio Space:

```python
from monitoring import SmolLM3Monitor

monitor = SmolLM3Monitor(
    experiment_name="my_experiment",
    trackio_url="https://your-space.hf.space",
    enable_tracking=True
)
```

### Step 3: Configure Space Settings

In your Space settings, ensure:
- **App file**: `app.py`
- **Python version**: 3.9 or higher
- **Hardware**: CPU (Basic) is sufficient

## Integration with Your Training Script

### Step 1: Update Your Configuration

Add Trackio settings to your training configuration:

```python
# config/train_smollm3.py
@dataclass
class SmolLM3Config:
    # ... existing settings ...
    
    # Trackio monitoring configuration
    enable_tracking: bool = True
    trackio_url: Optional[str] = None  # Your Space URL
    trackio_token: Optional[str] = None
    log_artifacts: bool = True
    log_metrics: bool = True
    log_config: bool = True
    experiment_name: Optional[str] = None
```

### Step 2: Run Training with Trackio

```bash
python train.py config/train_smollm3.py \
    --dataset_dir my_dataset \
    --enable_tracking \
    --trackio_url "https://your-username-trackio-monitoring.hf.space" \
    --experiment_name "smollm3_finetune_v1"
```

### Step 3: Monitor Your Experiments

1. **Create Experiment**: Use the "Create Experiment" tab in your Space
2. **Log Metrics**: Your training script will automatically log metrics
3. **View Results**: Use the "View Experiments" tab to see progress
4. **Update Status**: Mark experiments as completed when done

## Advanced Configuration

### Environment Variables

You can set Trackio configuration via environment variables:

```bash
export TRACKIO_URL="https://your-space.hf.space"
export TRACKIO_TOKEN="your_token_here"
```

### Custom Experiment Names

```bash
python train.py config/train_smollm3.py \
    --experiment_name "smollm3_high_lr_experiment" \
    --trackio_url "https://your-space.hf.space"
```

### Multiple Experiments

You can run multiple experiments and track them separately:

```bash
# Experiment 1
python train.py config/train_smollm3.py \
    --experiment_name "smollm3_baseline" \
    --learning_rate 2e-5

# Experiment 2
python train.py config/train_smollm3.py \
    --experiment_name "smollm3_high_lr" \
    --learning_rate 5e-5
```

## Using the Trackio Interface

### Creating Experiments

1. Go to the "Create Experiment" tab
2. Enter experiment name (e.g., "smollm3_finetune_v1")
3. Add description (optional)
4. Click "Create Experiment"
5. Note the experiment ID for logging metrics

### Logging Metrics

1. Go to the "Log Metrics" tab
2. Enter your experiment ID
3. Add metrics in JSON format:
   ```json
   {
     "loss": 0.5,
     "accuracy": 0.85,
     "learning_rate": 2e-5
   }
   ```
4. Add step number (optional)
5. Click "Log Metrics"

### Viewing Experiments

1. Go to the "View Experiments" tab
2. Enter experiment ID to view specific experiment
3. Or click "List All Experiments" to see all experiments

### Updating Status

1. Go to the "Update Status" tab
2. Enter experiment ID
3. Select new status (running, completed, failed, paused)
4. Click "Update Status"

## Troubleshooting

### Common Issues

#### 1. Space Not Building
- Check that all required files are uploaded
- Verify `app.py` is the main file
- Check the Space logs for errors

#### 2. Connection Errors
- Verify your Space URL is correct
- Check that the Space is running (not paused)
- Ensure your training script can reach the Space URL

#### 3. Missing Metrics
- Check that `enable_tracking=True` in your config
- Verify the Trackio URL is correct
- Check training logs for monitoring errors

#### 4. Authentication Issues
- If using tokens, verify they're correct
- Check Hugging Face account permissions
- Ensure Space is public or you have access

### Debug Mode

Enable debug logging in your training script:

```python
import logging
logging.basicConfig(level=logging.DEBUG)
```

### Manual Testing

Test the Trackio interface manually:

1. Create an experiment
2. Log some test metrics
3. View the experiment details
4. Update the status

## Security Considerations

### Public vs Private Spaces

- **Public Spaces**: Anyone can view and use the interface
- **Private Spaces**: Only you and collaborators can access

### Token Management

- Store tokens securely (environment variables)
- Don't commit tokens to version control
- Use Hugging Face's token management

### Data Privacy

- Trackio stores experiment data in the Space
- Consider data retention policies
- Be mindful of sensitive information in experiment names

## Performance Optimization

### Space Configuration

- Use CPU (Basic) for the interface (sufficient for tracking)
- Consider GPU only for actual training
- Monitor Space usage and limits

### Efficient Logging

- Log metrics at reasonable intervals (every 10-100 steps)
- Avoid logging too frequently to prevent rate limiting
- Use batch logging when possible

## Monitoring Best Practices

### Experiment Naming

Use descriptive names:
- `smollm3_baseline_v1`
- `smollm3_high_lr_experiment`
- `smollm3_dpo_training`

### Metric Logging

Log relevant metrics:
- Training loss
- Validation loss
- Learning rate
- GPU memory usage
- Training time

### Status Management

- Mark experiments as "running" when starting
- Update to "completed" when finished
- Mark as "failed" if errors occur
- Use "paused" for temporary stops

## Integration Examples

### Basic Integration

```python
from monitoring import SmolLM3Monitor

# Initialize monitor
monitor = SmolLM3Monitor(
    experiment_name="my_experiment",
    trackio_url="https://your-space.hf.space",
    enable_tracking=True
)

# Log configuration
monitor.log_config(config_dict)

# Log metrics during training
monitor.log_metrics({"loss": 0.5}, step=100)

# Log final results
monitor.log_training_summary(final_results)
```

### Advanced Integration

```python
# Custom monitoring setup
monitor = SmolLM3Monitor(
    experiment_name="smollm3_advanced",
    trackio_url="https://your-space.hf.space",
    enable_tracking=True,
    log_artifacts=True,
    log_metrics=True,
    log_config=True
)

# Log system metrics
monitor.log_system_metrics(step=current_step)

# Log model checkpoint
monitor.log_model_checkpoint("checkpoint-1000", step=1000)

# Log evaluation results
monitor.log_evaluation_results(eval_results, step=1000)
```

## Support and Resources

### Documentation

- [Hugging Face Spaces Documentation](https://huggingface.co/docs/hub/spaces)
- [Gradio Documentation](https://gradio.app/docs/)
- [Trackio GitHub Repository](https://github.com/Josephrp/trackio)

### Community

- [Hugging Face Forums](https://discuss.huggingface.co/)
- [Gradio Discord](https://discord.gg/feTf9z3Z)

### Issues and Feedback

- Report issues on the project repository
- Provide feedback on the Trackio interface
- Suggest improvements for the monitoring system

## Conclusion

You now have a complete Trackio monitoring system deployed on Hugging Face Spaces! This setup provides:

- βœ… Easy experiment tracking and monitoring
- βœ… Real-time metric logging
- βœ… Web-based interface for experiment management
- βœ… Integration with your SmolLM3 fine-tuning pipeline
- βœ… Scalable and accessible monitoring solution

Start tracking your experiments and gain insights into your model training process!