omgkit 2.20.0 → 2.21.1
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.
- package/README.md +125 -10
- package/package.json +1 -1
- package/plugin/agents/ai-architect-agent.md +282 -0
- package/plugin/agents/data-scientist-agent.md +221 -0
- package/plugin/agents/experiment-analyst-agent.md +318 -0
- package/plugin/agents/ml-engineer-agent.md +165 -0
- package/plugin/agents/mlops-engineer-agent.md +324 -0
- package/plugin/agents/model-optimizer-agent.md +287 -0
- package/plugin/agents/production-engineer-agent.md +360 -0
- package/plugin/agents/research-scientist-agent.md +274 -0
- package/plugin/commands/omgdata/augment.md +86 -0
- package/plugin/commands/omgdata/collect.md +81 -0
- package/plugin/commands/omgdata/label.md +83 -0
- package/plugin/commands/omgdata/split.md +83 -0
- package/plugin/commands/omgdata/validate.md +76 -0
- package/plugin/commands/omgdata/version.md +85 -0
- package/plugin/commands/omgdeploy/ab.md +94 -0
- package/plugin/commands/omgdeploy/cloud.md +89 -0
- package/plugin/commands/omgdeploy/edge.md +93 -0
- package/plugin/commands/omgdeploy/package.md +91 -0
- package/plugin/commands/omgdeploy/serve.md +92 -0
- package/plugin/commands/omgfeature/embed.md +93 -0
- package/plugin/commands/omgfeature/extract.md +93 -0
- package/plugin/commands/omgfeature/select.md +85 -0
- package/plugin/commands/omgfeature/store.md +97 -0
- package/plugin/commands/omgml/init.md +60 -0
- package/plugin/commands/omgml/status.md +82 -0
- package/plugin/commands/omgops/drift.md +87 -0
- package/plugin/commands/omgops/monitor.md +99 -0
- package/plugin/commands/omgops/pipeline.md +102 -0
- package/plugin/commands/omgops/registry.md +109 -0
- package/plugin/commands/omgops/retrain.md +91 -0
- package/plugin/commands/omgoptim/distill.md +90 -0
- package/plugin/commands/omgoptim/profile.md +92 -0
- package/plugin/commands/omgoptim/prune.md +81 -0
- package/plugin/commands/omgoptim/quantize.md +83 -0
- package/plugin/commands/omgtrain/baseline.md +78 -0
- package/plugin/commands/omgtrain/compare.md +99 -0
- package/plugin/commands/omgtrain/evaluate.md +85 -0
- package/plugin/commands/omgtrain/train.md +81 -0
- package/plugin/commands/omgtrain/tune.md +89 -0
- package/plugin/registry.yaml +252 -2
- package/plugin/skills/ml-systems/SKILL.md +65 -0
- package/plugin/skills/ml-systems/ai-accelerators/SKILL.md +342 -0
- package/plugin/skills/ml-systems/data-eng/SKILL.md +126 -0
- package/plugin/skills/ml-systems/deep-learning-primer/SKILL.md +143 -0
- package/plugin/skills/ml-systems/deployment-paradigms/SKILL.md +148 -0
- package/plugin/skills/ml-systems/dnn-architectures/SKILL.md +128 -0
- package/plugin/skills/ml-systems/edge-deployment/SKILL.md +366 -0
- package/plugin/skills/ml-systems/efficient-ai/SKILL.md +316 -0
- package/plugin/skills/ml-systems/feature-engineering/SKILL.md +151 -0
- package/plugin/skills/ml-systems/ml-frameworks/SKILL.md +187 -0
- package/plugin/skills/ml-systems/ml-serving-optimization/SKILL.md +371 -0
- package/plugin/skills/ml-systems/ml-systems-fundamentals/SKILL.md +103 -0
- package/plugin/skills/ml-systems/ml-workflow/SKILL.md +162 -0
- package/plugin/skills/ml-systems/mlops/SKILL.md +386 -0
- package/plugin/skills/ml-systems/model-deployment/SKILL.md +350 -0
- package/plugin/skills/ml-systems/model-dev/SKILL.md +160 -0
- package/plugin/skills/ml-systems/model-optimization/SKILL.md +339 -0
- package/plugin/skills/ml-systems/robust-ai/SKILL.md +395 -0
- package/plugin/skills/ml-systems/training-data/SKILL.md +152 -0
- package/plugin/workflows/ml-systems/data-preparation-workflow.md +276 -0
- package/plugin/workflows/ml-systems/edge-deployment-workflow.md +413 -0
- package/plugin/workflows/ml-systems/full-ml-lifecycle-workflow.md +405 -0
- package/plugin/workflows/ml-systems/hyperparameter-tuning-workflow.md +352 -0
- package/plugin/workflows/ml-systems/mlops-pipeline-workflow.md +384 -0
- package/plugin/workflows/ml-systems/model-deployment-workflow.md +392 -0
- package/plugin/workflows/ml-systems/model-development-workflow.md +218 -0
- package/plugin/workflows/ml-systems/model-evaluation-workflow.md +416 -0
- package/plugin/workflows/ml-systems/model-optimization-workflow.md +390 -0
- package/plugin/workflows/ml-systems/monitoring-drift-workflow.md +446 -0
- package/plugin/workflows/ml-systems/retraining-workflow.md +401 -0
- package/plugin/workflows/ml-systems/training-pipeline-workflow.md +382 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: data-engineering
|
|
3
|
+
description: ML data engineering covering data pipelines, data quality, collection strategies, storage, and versioning for machine learning systems.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Data Engineering for ML
|
|
7
|
+
|
|
8
|
+
Building robust data infrastructure for ML systems.
|
|
9
|
+
|
|
10
|
+
## Data Pipeline Architecture
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
14
|
+
│ ML DATA PIPELINE │
|
|
15
|
+
├─────────────────────────────────────────────────────────────┤
|
|
16
|
+
│ │
|
|
17
|
+
│ COLLECTION → VALIDATION → PROCESSING → STORAGE │
|
|
18
|
+
│ ↓ ↓ ↓ ↓ │
|
|
19
|
+
│ Sources Schema Check Transform Data Lake │
|
|
20
|
+
│ APIs Quality Check Normalize Feature Store │
|
|
21
|
+
│ DBs Statistics Encode Model Registry │
|
|
22
|
+
│ │
|
|
23
|
+
└─────────────────────────────────────────────────────────────┘
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Data Collection
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from dataclasses import dataclass
|
|
30
|
+
from typing import List, Dict
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class DataSource:
|
|
34
|
+
name: str
|
|
35
|
+
type: str # database, api, file, stream
|
|
36
|
+
connection: Dict
|
|
37
|
+
|
|
38
|
+
class DataCollector:
|
|
39
|
+
def __init__(self, sources: List[DataSource]):
|
|
40
|
+
self.sources = sources
|
|
41
|
+
|
|
42
|
+
def collect(self, source_name: str) -> pd.DataFrame:
|
|
43
|
+
source = next(s for s in self.sources if s.name == source_name)
|
|
44
|
+
|
|
45
|
+
if source.type == "database":
|
|
46
|
+
return pd.read_sql(source.connection["query"],
|
|
47
|
+
source.connection["conn"])
|
|
48
|
+
elif source.type == "api":
|
|
49
|
+
response = requests.get(source.connection["url"])
|
|
50
|
+
return pd.DataFrame(response.json())
|
|
51
|
+
elif source.type == "file":
|
|
52
|
+
return pd.read_parquet(source.connection["path"])
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Data Quality
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import great_expectations as ge
|
|
59
|
+
|
|
60
|
+
def validate_data(df: pd.DataFrame, expectations_path: str) -> bool:
|
|
61
|
+
ge_df = ge.from_pandas(df)
|
|
62
|
+
|
|
63
|
+
# Schema validation
|
|
64
|
+
assert ge_df.expect_column_to_exist("user_id").success
|
|
65
|
+
assert ge_df.expect_column_values_to_not_be_null("user_id").success
|
|
66
|
+
assert ge_df.expect_column_values_to_be_unique("user_id").success
|
|
67
|
+
|
|
68
|
+
# Value validation
|
|
69
|
+
assert ge_df.expect_column_values_to_be_between(
|
|
70
|
+
"age", min_value=0, max_value=150
|
|
71
|
+
).success
|
|
72
|
+
|
|
73
|
+
# Statistical validation
|
|
74
|
+
assert ge_df.expect_column_mean_to_be_between(
|
|
75
|
+
"purchase_amount", min_value=0, max_value=10000
|
|
76
|
+
).success
|
|
77
|
+
|
|
78
|
+
return True
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Data Versioning
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
# DVC for data versioning
|
|
85
|
+
# dvc init
|
|
86
|
+
# dvc add data/processed/
|
|
87
|
+
|
|
88
|
+
import dvc.api
|
|
89
|
+
|
|
90
|
+
# Load specific version
|
|
91
|
+
data_url = dvc.api.get_url(
|
|
92
|
+
path='data/processed/train.parquet',
|
|
93
|
+
repo='https://github.com/org/repo',
|
|
94
|
+
rev='v1.2.0'
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
# Track changes
|
|
98
|
+
def version_data(data_path: str, message: str):
|
|
99
|
+
import subprocess
|
|
100
|
+
subprocess.run(["dvc", "add", data_path])
|
|
101
|
+
subprocess.run(["git", "add", f"{data_path}.dvc"])
|
|
102
|
+
subprocess.run(["git", "commit", "-m", message])
|
|
103
|
+
subprocess.run(["dvc", "push"])
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Data Storage Patterns
|
|
107
|
+
|
|
108
|
+
| Pattern | Use Case | Technology |
|
|
109
|
+
|---------|----------|------------|
|
|
110
|
+
| Data Lake | Raw storage | S3, GCS, ADLS |
|
|
111
|
+
| Data Warehouse | Analytics | Snowflake, BigQuery |
|
|
112
|
+
| Feature Store | ML features | Feast, Tecton |
|
|
113
|
+
| Vector Store | Embeddings | Pinecone, Weaviate |
|
|
114
|
+
|
|
115
|
+
## Commands
|
|
116
|
+
- `/omgdata:collect` - Data collection
|
|
117
|
+
- `/omgdata:validate` - Data validation
|
|
118
|
+
- `/omgdata:version` - Version data
|
|
119
|
+
|
|
120
|
+
## Best Practices
|
|
121
|
+
|
|
122
|
+
1. Validate data at every stage
|
|
123
|
+
2. Version all data assets
|
|
124
|
+
3. Document data schemas
|
|
125
|
+
4. Monitor data quality metrics
|
|
126
|
+
5. Implement data lineage tracking
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deep-learning-primer
|
|
3
|
+
description: Deep learning foundations including neural network basics, backpropagation, optimization, regularization, and training best practices.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Deep Learning Primer
|
|
7
|
+
|
|
8
|
+
Essential deep learning concepts for ML systems.
|
|
9
|
+
|
|
10
|
+
## Neural Network Basics
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
import torch
|
|
14
|
+
import torch.nn as nn
|
|
15
|
+
|
|
16
|
+
class MLP(nn.Module):
|
|
17
|
+
def __init__(self, input_dim, hidden_dim, output_dim):
|
|
18
|
+
super().__init__()
|
|
19
|
+
self.layers = nn.Sequential(
|
|
20
|
+
nn.Linear(input_dim, hidden_dim),
|
|
21
|
+
nn.ReLU(),
|
|
22
|
+
nn.Dropout(0.2),
|
|
23
|
+
nn.Linear(hidden_dim, hidden_dim),
|
|
24
|
+
nn.ReLU(),
|
|
25
|
+
nn.Dropout(0.2),
|
|
26
|
+
nn.Linear(hidden_dim, output_dim)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def forward(self, x):
|
|
30
|
+
return self.layers(x)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Activation Functions
|
|
34
|
+
|
|
35
|
+
| Function | Use Case | Output Range |
|
|
36
|
+
|----------|----------|--------------|
|
|
37
|
+
| ReLU | Hidden layers | [0, ∞) |
|
|
38
|
+
| LeakyReLU | Prevent dead neurons | (-∞, ∞) |
|
|
39
|
+
| GELU | Transformers | (-∞, ∞) |
|
|
40
|
+
| Sigmoid | Binary classification | (0, 1) |
|
|
41
|
+
| Softmax | Multi-class | (0, 1) |
|
|
42
|
+
| Tanh | Centered output | (-1, 1) |
|
|
43
|
+
|
|
44
|
+
## Loss Functions
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
# Classification
|
|
48
|
+
cross_entropy = nn.CrossEntropyLoss()
|
|
49
|
+
binary_ce = nn.BCEWithLogitsLoss()
|
|
50
|
+
focal_loss = lambda p, y, gamma=2: -((1-p)**gamma * y * torch.log(p))
|
|
51
|
+
|
|
52
|
+
# Regression
|
|
53
|
+
mse = nn.MSELoss()
|
|
54
|
+
mae = nn.L1Loss()
|
|
55
|
+
huber = nn.HuberLoss()
|
|
56
|
+
|
|
57
|
+
# Custom loss
|
|
58
|
+
def contrastive_loss(embeddings, labels, margin=1.0):
|
|
59
|
+
distances = torch.cdist(embeddings, embeddings)
|
|
60
|
+
same_class = labels.unsqueeze(0) == labels.unsqueeze(1)
|
|
61
|
+
loss = same_class * distances + (~same_class) * F.relu(margin - distances)
|
|
62
|
+
return loss.mean()
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Optimization
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
# Optimizers
|
|
69
|
+
optimizer = torch.optim.AdamW(
|
|
70
|
+
model.parameters(),
|
|
71
|
+
lr=1e-3,
|
|
72
|
+
weight_decay=0.01
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
# Learning rate scheduling
|
|
76
|
+
scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(
|
|
77
|
+
optimizer,
|
|
78
|
+
T_max=num_epochs
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# Training loop
|
|
82
|
+
for epoch in range(num_epochs):
|
|
83
|
+
for batch in dataloader:
|
|
84
|
+
optimizer.zero_grad()
|
|
85
|
+
loss = criterion(model(batch.x), batch.y)
|
|
86
|
+
loss.backward()
|
|
87
|
+
torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)
|
|
88
|
+
optimizer.step()
|
|
89
|
+
scheduler.step()
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Regularization Techniques
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# Dropout
|
|
96
|
+
nn.Dropout(p=0.5)
|
|
97
|
+
|
|
98
|
+
# Weight decay (L2)
|
|
99
|
+
optimizer = AdamW(params, weight_decay=0.01)
|
|
100
|
+
|
|
101
|
+
# Batch normalization
|
|
102
|
+
nn.BatchNorm1d(num_features)
|
|
103
|
+
|
|
104
|
+
# Layer normalization (for transformers)
|
|
105
|
+
nn.LayerNorm(hidden_dim)
|
|
106
|
+
|
|
107
|
+
# Early stopping
|
|
108
|
+
class EarlyStopping:
|
|
109
|
+
def __init__(self, patience=5):
|
|
110
|
+
self.patience = patience
|
|
111
|
+
self.counter = 0
|
|
112
|
+
self.best_score = None
|
|
113
|
+
|
|
114
|
+
def __call__(self, val_loss):
|
|
115
|
+
if self.best_score is None or val_loss < self.best_score:
|
|
116
|
+
self.best_score = val_loss
|
|
117
|
+
self.counter = 0
|
|
118
|
+
else:
|
|
119
|
+
self.counter += 1
|
|
120
|
+
return self.counter >= self.patience
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Initialization
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
def init_weights(module):
|
|
127
|
+
if isinstance(module, nn.Linear):
|
|
128
|
+
nn.init.xavier_uniform_(module.weight)
|
|
129
|
+
if module.bias is not None:
|
|
130
|
+
nn.init.zeros_(module.bias)
|
|
131
|
+
elif isinstance(module, nn.Embedding):
|
|
132
|
+
nn.init.normal_(module.weight, std=0.02)
|
|
133
|
+
|
|
134
|
+
model.apply(init_weights)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Best Practices
|
|
138
|
+
|
|
139
|
+
1. Start with Adam optimizer, lr=1e-3
|
|
140
|
+
2. Use learning rate warmup
|
|
141
|
+
3. Apply gradient clipping
|
|
142
|
+
4. Monitor training/validation gap
|
|
143
|
+
5. Use mixed precision training
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: deployment-paradigms
|
|
3
|
+
description: ML deployment paradigms including batch vs real-time inference, online vs offline serving, edge deployment, and serverless ML.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Deployment Paradigms
|
|
7
|
+
|
|
8
|
+
Understanding ML deployment patterns and trade-offs.
|
|
9
|
+
|
|
10
|
+
## Deployment Modes
|
|
11
|
+
|
|
12
|
+
### Batch Inference
|
|
13
|
+
```python
|
|
14
|
+
# Process all data at once
|
|
15
|
+
def batch_inference(model, data_path, output_path):
|
|
16
|
+
data = pd.read_parquet(data_path)
|
|
17
|
+
predictions = model.predict(data)
|
|
18
|
+
predictions.to_parquet(output_path)
|
|
19
|
+
|
|
20
|
+
# Schedule: Daily/Hourly
|
|
21
|
+
# Airflow DAG example
|
|
22
|
+
with DAG('batch_inference', schedule_interval='@daily') as dag:
|
|
23
|
+
inference_task = PythonOperator(
|
|
24
|
+
task_id='run_inference',
|
|
25
|
+
python_callable=batch_inference
|
|
26
|
+
)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Real-time Inference
|
|
30
|
+
```python
|
|
31
|
+
from fastapi import FastAPI
|
|
32
|
+
import torch
|
|
33
|
+
|
|
34
|
+
app = FastAPI()
|
|
35
|
+
model = torch.jit.load("model.pt")
|
|
36
|
+
|
|
37
|
+
@app.post("/predict")
|
|
38
|
+
async def predict(request: PredictRequest):
|
|
39
|
+
features = preprocess(request.data)
|
|
40
|
+
with torch.no_grad():
|
|
41
|
+
prediction = model(features)
|
|
42
|
+
return {"prediction": prediction.tolist()}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Streaming Inference
|
|
46
|
+
```python
|
|
47
|
+
from kafka import KafkaConsumer, KafkaProducer
|
|
48
|
+
|
|
49
|
+
consumer = KafkaConsumer('input-topic')
|
|
50
|
+
producer = KafkaProducer()
|
|
51
|
+
|
|
52
|
+
for message in consumer:
|
|
53
|
+
data = deserialize(message.value)
|
|
54
|
+
prediction = model.predict(data)
|
|
55
|
+
producer.send('output-topic', serialize(prediction))
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Serving Patterns
|
|
59
|
+
|
|
60
|
+
### Online Serving
|
|
61
|
+
- Sub-second latency
|
|
62
|
+
- Feature store for features
|
|
63
|
+
- Model caching
|
|
64
|
+
- Auto-scaling
|
|
65
|
+
|
|
66
|
+
### Offline Serving
|
|
67
|
+
- Batch processing
|
|
68
|
+
- Precomputed predictions
|
|
69
|
+
- Lower cost
|
|
70
|
+
- Higher throughput
|
|
71
|
+
|
|
72
|
+
### Hybrid Serving
|
|
73
|
+
```python
|
|
74
|
+
class HybridPredictor:
|
|
75
|
+
def __init__(self, cache_ttl=3600):
|
|
76
|
+
self.cache = {}
|
|
77
|
+
self.cache_ttl = cache_ttl
|
|
78
|
+
self.model = load_model()
|
|
79
|
+
|
|
80
|
+
def predict(self, user_id, context):
|
|
81
|
+
# Check precomputed cache
|
|
82
|
+
cache_key = f"{user_id}:{hash(context)}"
|
|
83
|
+
if cache_key in self.cache:
|
|
84
|
+
return self.cache[cache_key]
|
|
85
|
+
|
|
86
|
+
# Compute real-time
|
|
87
|
+
prediction = self.model.predict(context)
|
|
88
|
+
self.cache[cache_key] = prediction
|
|
89
|
+
return prediction
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Edge Deployment
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# TFLite for mobile/embedded
|
|
96
|
+
import tensorflow as tf
|
|
97
|
+
|
|
98
|
+
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
|
|
99
|
+
converter.optimizations = [tf.lite.Optimize.DEFAULT]
|
|
100
|
+
tflite_model = converter.convert()
|
|
101
|
+
|
|
102
|
+
# ONNX for cross-platform
|
|
103
|
+
import onnx
|
|
104
|
+
torch.onnx.export(model, dummy_input, "model.onnx")
|
|
105
|
+
|
|
106
|
+
# CoreML for iOS
|
|
107
|
+
import coremltools as ct
|
|
108
|
+
mlmodel = ct.convert(model, inputs=[ct.TensorType(shape=(1, 3, 224, 224))])
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Serverless ML
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# AWS Lambda
|
|
115
|
+
import json
|
|
116
|
+
import boto3
|
|
117
|
+
|
|
118
|
+
def lambda_handler(event, context):
|
|
119
|
+
runtime = boto3.client('runtime.sagemaker')
|
|
120
|
+
response = runtime.invoke_endpoint(
|
|
121
|
+
EndpointName='my-model',
|
|
122
|
+
ContentType='application/json',
|
|
123
|
+
Body=json.dumps(event['body'])
|
|
124
|
+
)
|
|
125
|
+
return json.loads(response['Body'].read())
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Deployment Comparison
|
|
129
|
+
|
|
130
|
+
| Pattern | Latency | Cost | Complexity | Use Case |
|
|
131
|
+
|---------|---------|------|------------|----------|
|
|
132
|
+
| Batch | High | Low | Low | Reports, ETL |
|
|
133
|
+
| Real-time | Low | High | Medium | User-facing |
|
|
134
|
+
| Streaming | Medium | Medium | High | Event-driven |
|
|
135
|
+
| Edge | Very Low | Low | High | Offline, IoT |
|
|
136
|
+
| Serverless | Variable | Pay-per-use | Low | Sporadic traffic |
|
|
137
|
+
|
|
138
|
+
## Commands
|
|
139
|
+
- `/omgdeploy:serve` - Deploy serving
|
|
140
|
+
- `/omgdeploy:edge` - Edge deployment
|
|
141
|
+
|
|
142
|
+
## Best Practices
|
|
143
|
+
|
|
144
|
+
1. Match paradigm to requirements
|
|
145
|
+
2. Consider latency vs cost trade-offs
|
|
146
|
+
3. Plan for scaling
|
|
147
|
+
4. Test under realistic conditions
|
|
148
|
+
5. Monitor deployed models
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dnn-architectures
|
|
3
|
+
description: Deep neural network architectures including CNNs, RNNs, Transformers, and modern architectures for vision, NLP, and multimodal tasks.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# DNN Architectures
|
|
7
|
+
|
|
8
|
+
Modern deep neural network architectures.
|
|
9
|
+
|
|
10
|
+
## Convolutional Neural Networks
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
import torch.nn as nn
|
|
14
|
+
|
|
15
|
+
class CNN(nn.Module):
|
|
16
|
+
def __init__(self, num_classes=10):
|
|
17
|
+
super().__init__()
|
|
18
|
+
self.features = nn.Sequential(
|
|
19
|
+
nn.Conv2d(3, 64, kernel_size=3, padding=1),
|
|
20
|
+
nn.BatchNorm2d(64),
|
|
21
|
+
nn.ReLU(),
|
|
22
|
+
nn.MaxPool2d(2),
|
|
23
|
+
nn.Conv2d(64, 128, kernel_size=3, padding=1),
|
|
24
|
+
nn.BatchNorm2d(128),
|
|
25
|
+
nn.ReLU(),
|
|
26
|
+
nn.MaxPool2d(2),
|
|
27
|
+
nn.Conv2d(128, 256, kernel_size=3, padding=1),
|
|
28
|
+
nn.BatchNorm2d(256),
|
|
29
|
+
nn.ReLU(),
|
|
30
|
+
nn.AdaptiveAvgPool2d(1)
|
|
31
|
+
)
|
|
32
|
+
self.classifier = nn.Linear(256, num_classes)
|
|
33
|
+
|
|
34
|
+
def forward(self, x):
|
|
35
|
+
x = self.features(x)
|
|
36
|
+
x = x.view(x.size(0), -1)
|
|
37
|
+
return self.classifier(x)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Transformer Architecture
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
class TransformerBlock(nn.Module):
|
|
44
|
+
def __init__(self, d_model, n_heads, d_ff, dropout=0.1):
|
|
45
|
+
super().__init__()
|
|
46
|
+
self.attn = nn.MultiheadAttention(d_model, n_heads, dropout=dropout)
|
|
47
|
+
self.ff = nn.Sequential(
|
|
48
|
+
nn.Linear(d_model, d_ff),
|
|
49
|
+
nn.GELU(),
|
|
50
|
+
nn.Dropout(dropout),
|
|
51
|
+
nn.Linear(d_ff, d_model)
|
|
52
|
+
)
|
|
53
|
+
self.ln1 = nn.LayerNorm(d_model)
|
|
54
|
+
self.ln2 = nn.LayerNorm(d_model)
|
|
55
|
+
self.dropout = nn.Dropout(dropout)
|
|
56
|
+
|
|
57
|
+
def forward(self, x, mask=None):
|
|
58
|
+
# Self-attention with residual
|
|
59
|
+
attn_out, _ = self.attn(x, x, x, attn_mask=mask)
|
|
60
|
+
x = self.ln1(x + self.dropout(attn_out))
|
|
61
|
+
# Feedforward with residual
|
|
62
|
+
ff_out = self.ff(x)
|
|
63
|
+
x = self.ln2(x + self.dropout(ff_out))
|
|
64
|
+
return x
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Vision Transformer (ViT)
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
class ViT(nn.Module):
|
|
71
|
+
def __init__(self, image_size, patch_size, num_classes, d_model, n_heads, n_layers):
|
|
72
|
+
super().__init__()
|
|
73
|
+
num_patches = (image_size // patch_size) ** 2
|
|
74
|
+
self.patch_embed = nn.Conv2d(3, d_model, patch_size, patch_size)
|
|
75
|
+
self.cls_token = nn.Parameter(torch.zeros(1, 1, d_model))
|
|
76
|
+
self.pos_embed = nn.Parameter(torch.zeros(1, num_patches + 1, d_model))
|
|
77
|
+
self.transformer = nn.ModuleList([
|
|
78
|
+
TransformerBlock(d_model, n_heads, d_model * 4)
|
|
79
|
+
for _ in range(n_layers)
|
|
80
|
+
])
|
|
81
|
+
self.head = nn.Linear(d_model, num_classes)
|
|
82
|
+
|
|
83
|
+
def forward(self, x):
|
|
84
|
+
patches = self.patch_embed(x).flatten(2).transpose(1, 2)
|
|
85
|
+
cls_tokens = self.cls_token.expand(x.size(0), -1, -1)
|
|
86
|
+
x = torch.cat([cls_tokens, patches], dim=1)
|
|
87
|
+
x = x + self.pos_embed
|
|
88
|
+
for block in self.transformer:
|
|
89
|
+
x = block(x)
|
|
90
|
+
return self.head(x[:, 0])
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Architecture Comparison
|
|
94
|
+
|
|
95
|
+
| Architecture | Best For | Params | Inference |
|
|
96
|
+
|--------------|----------|--------|-----------|
|
|
97
|
+
| ResNet | Image classification | 25M | Fast |
|
|
98
|
+
| EfficientNet | Efficient vision | 5-66M | Efficient |
|
|
99
|
+
| ViT | Vision + scale | 86-632M | GPU optimized |
|
|
100
|
+
| BERT | NLP understanding | 110-340M | Moderate |
|
|
101
|
+
| GPT | Text generation | 117M-175B | Heavy |
|
|
102
|
+
| T5 | Seq2seq tasks | 60M-11B | Heavy |
|
|
103
|
+
|
|
104
|
+
## Modern Architectures
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
# Using pretrained models
|
|
108
|
+
from transformers import AutoModel
|
|
109
|
+
|
|
110
|
+
# Vision
|
|
111
|
+
vit = AutoModel.from_pretrained("google/vit-base-patch16-224")
|
|
112
|
+
clip = AutoModel.from_pretrained("openai/clip-vit-base-patch32")
|
|
113
|
+
|
|
114
|
+
# NLP
|
|
115
|
+
bert = AutoModel.from_pretrained("bert-base-uncased")
|
|
116
|
+
llama = AutoModel.from_pretrained("meta-llama/Llama-2-7b-hf")
|
|
117
|
+
|
|
118
|
+
# Multimodal
|
|
119
|
+
blip = AutoModel.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Best Practices
|
|
123
|
+
|
|
124
|
+
1. Use pretrained models when possible
|
|
125
|
+
2. Match architecture to task
|
|
126
|
+
3. Consider compute budget
|
|
127
|
+
4. Scale model size with data size
|
|
128
|
+
5. Monitor memory usage
|