Skip to content

Commit bc1393f

Browse files
committed
Add mock mode feature to README
1 parent 19245ec commit bc1393f

File tree

6 files changed

+28
-13
lines changed

6 files changed

+28
-13
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ This project contains two main components:
9191

9292
Try the minimal working demo (uses 20 sample QA pairs and simulated evaluation):
9393

94+
**Option 1: Mock Mode (No API Key Required)**
95+
```bash
96+
./run_demo.sh # Automatically uses mock mode if no API key
97+
```
98+
99+
**Option 2: Real Tinker Infrastructure**
94100
```bash
95101
export TINKER_API_KEY=sk-... # Your Tinker API key
96102
./run_demo.sh
97103
```
98104

99-
This will run 1-3 training rounds, automatically adjusting the learning rate and triggering Round 2 when scores fall below threshold (0.75). Perfect for understanding the loop before customizing it.
105+
This will run 1-3 training rounds, automatically adjusting the learning rate and triggering Round 2 when scores fall below threshold (0.75). Mock mode simulates training locally without cloud calls—perfect for understanding the loop before using real infrastructure.
100106

101107
See [DEMO.md](DEMO.md) for a detailed walkthrough of what happens during the demo run.
102108

data_loader.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66
from pathlib import Path
77
from typing import Any, Dict, List, Optional
88

9-
try:
10-
from tinker import types
11-
from tinker_cookbook import renderers
12-
except ImportError:
13-
types = None
9+
import os
10+
11+
USE_MOCK = os.getenv("TINKER_MOCK", "0") == "1"
12+
13+
if USE_MOCK:
14+
from mock_tinker import MockTypes
15+
types = MockTypes
1416
renderers = None
17+
else:
18+
try:
19+
from tinker import types
20+
from tinker_cookbook import renderers
21+
except ImportError:
22+
types = None
23+
renderers = None
1524

1625

1726
class DataLoader:
@@ -111,7 +120,7 @@ def prepare_training_data(
111120
Returns:
112121
List of tinker.types.Datum objects with proper loss masking.
113122
"""
114-
if types is None:
123+
if types is None and not USE_MOCK:
115124
raise ImportError("tinker package required for data preparation")
116125

117126
raw_examples = self.load_jsonl(train_file)

mock_checkpoints/round_1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "round_1", "mock": true}

mock_checkpoints/round_2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name": "round_2", "mock": true}

mock_tinker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@ async def forward_backward_async(self, datums: List[Any], loss_fn: str = "cross_
6464
await asyncio.sleep(0.01)
6565
self.step_count += 1
6666
self.current_loss *= 0.95
67+
current_loss_value = self.current_loss
6768

6869
class AsyncFuture:
69-
async def __await__(self):
70-
return {"loss": self.current_loss}
71-
7270
def __await__(self):
7371
async def _wait():
74-
return {"loss": self.current_loss}
72+
return {"loss": current_loss_value}
7573
return _wait().__await__()
7674

7775
return AsyncFuture()

trainer_with_eval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ async def async_main(config_path: str) -> None:
242242

243243
config = load_and_validate_config(config_path)
244244

245-
if tinker is None:
246-
raise ImportError("The `tinker` package is not installed. Please install it via `pip install tinker`.")
245+
if tinker is None and not USE_MOCK:
246+
raise ImportError("The `tinker` package is not installed. Please install it via `pip install tinker` or run in mock mode with TINKER_MOCK=1.")
247247

248248
service_client = tinker.ServiceClient()
249249
base_model = config.base_model

0 commit comments

Comments
 (0)