loglog-ml 0.1.0__py3-none-any.whl
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.
- loglog/__init__.py +485 -0
- loglog/cli.py +227 -0
- loglog/sdk/__init__.py +1 -0
- loglog/sdk/api.py +208 -0
- loglog/sdk/capture.py +172 -0
- loglog/sdk/config.py +145 -0
- loglog/sdk/run.py +832 -0
- loglog/sdk/summary.py +123 -0
- loglog/sdk/telemetry.py +116 -0
- loglog/sdk/types.py +481 -0
- loglog/sdk/writer.py +184 -0
- loglog/server/__init__.py +1 -0
- loglog/server/app.py +288 -0
- loglog/server/static/assets/index-Bvdhw2gO.css +1 -0
- loglog/server/static/assets/index-C4BFgHF7.js +66 -0
- loglog/server/static/index.html +13 -0
- loglog/server/static/report_template.html +73 -0
- loglog/storage/__init__.py +1 -0
- loglog/storage/index.py +247 -0
- loglog/storage/layout.py +341 -0
- loglog/storage/reader.py +161 -0
- loglog/storage/reports.py +320 -0
- loglog/storage/scanner.py +431 -0
- loglog/storage/tfevents.py +415 -0
- loglog_ml-0.1.0.dist-info/METADATA +124 -0
- loglog_ml-0.1.0.dist-info/RECORD +29 -0
- loglog_ml-0.1.0.dist-info/WHEEL +4 -0
- loglog_ml-0.1.0.dist-info/entry_points.txt +2 -0
- loglog_ml-0.1.0.dist-info/licenses/LICENSE +21 -0
loglog/__init__.py
ADDED
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
"""LogLog: local-first, zero-API-key Weights & Biases drop-in & TensorBoard alternative."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
import types
|
|
8
|
+
import warnings
|
|
9
|
+
from collections.abc import Mapping, Sequence
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from loglog.sdk.api import Api, ApiRun
|
|
13
|
+
from loglog.sdk.config import Config
|
|
14
|
+
from loglog.sdk.run import DisabledRun, Run
|
|
15
|
+
from loglog.sdk.summary import Summary
|
|
16
|
+
from loglog.sdk.types import AlertLevel, Artifact, CustomChart, Histogram, Html, Image, Settings, Table, plot
|
|
17
|
+
|
|
18
|
+
__version__ = "0.1.0"
|
|
19
|
+
|
|
20
|
+
# Active run (literally None when inactive so `if wandb.run is not None:` works identically to W&B)
|
|
21
|
+
run: Run | DisabledRun | None = None
|
|
22
|
+
|
|
23
|
+
_WARNED_NOOPS: set[str] = set()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class _RunProxy:
|
|
27
|
+
"""Module-level proxy for `loglog.config` and `loglog.summary`."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, attr: str) -> None:
|
|
30
|
+
self._attr = attr
|
|
31
|
+
self._fallback = Config() if attr == "config" else Summary()
|
|
32
|
+
|
|
33
|
+
def _target(self) -> Any:
|
|
34
|
+
if run is not None:
|
|
35
|
+
return getattr(run, self._attr)
|
|
36
|
+
return self._fallback
|
|
37
|
+
|
|
38
|
+
def __getattr__(self, item: str) -> Any:
|
|
39
|
+
return getattr(self._target(), item)
|
|
40
|
+
|
|
41
|
+
def __getitem__(self, key: str) -> Any:
|
|
42
|
+
return self._target()[key]
|
|
43
|
+
|
|
44
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
45
|
+
self._target()[key] = value
|
|
46
|
+
|
|
47
|
+
def __contains__(self, key: object) -> bool:
|
|
48
|
+
return key in self._target()
|
|
49
|
+
|
|
50
|
+
def __iter__(self):
|
|
51
|
+
return iter(self._target())
|
|
52
|
+
|
|
53
|
+
def __len__(self) -> int:
|
|
54
|
+
return len(self._target())
|
|
55
|
+
|
|
56
|
+
def __repr__(self) -> str:
|
|
57
|
+
return repr(self._target())
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
config: Any = _RunProxy("config")
|
|
61
|
+
summary: Any = _RunProxy("summary")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class _EnvNamespace:
|
|
65
|
+
"""W&B `wandb.env` compatibility namespace (used by HF Transformers / Accelerate)."""
|
|
66
|
+
|
|
67
|
+
PROJECT = "WANDB_PROJECT"
|
|
68
|
+
ENTITY = "WANDB_ENTITY"
|
|
69
|
+
MODE = "WANDB_MODE"
|
|
70
|
+
DIR = "WANDB_DIR"
|
|
71
|
+
NAME = "WANDB_NAME"
|
|
72
|
+
RUN_GROUP = "WANDB_RUN_GROUP"
|
|
73
|
+
RUN_ID = "WANDB_RUN_ID"
|
|
74
|
+
NOTES = "WANDB_NOTES"
|
|
75
|
+
TAGS = "WANDB_TAGS"
|
|
76
|
+
DISABLED = "WANDB_DISABLED"
|
|
77
|
+
|
|
78
|
+
@staticmethod
|
|
79
|
+
def set_entity(value: str, env: dict[str, str] | None = None) -> None:
|
|
80
|
+
(os.environ if env is None else env)["WANDB_ENTITY"] = str(value)
|
|
81
|
+
|
|
82
|
+
@staticmethod
|
|
83
|
+
def set_project(value: str, env: dict[str, str] | None = None) -> None:
|
|
84
|
+
(os.environ if env is None else env)["WANDB_PROJECT"] = str(value)
|
|
85
|
+
|
|
86
|
+
@staticmethod
|
|
87
|
+
def get_project(default: str | None = None, env: Mapping[str, str] | None = None) -> str | None:
|
|
88
|
+
e = os.environ if env is None else env
|
|
89
|
+
return e.get("LOGLOG_PROJECT") or e.get("WANDB_PROJECT") or default
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
def get_entity(default: str | None = None, env: Mapping[str, str] | None = None) -> str | None:
|
|
93
|
+
e = os.environ if env is None else env
|
|
94
|
+
return e.get("LOGLOG_ENTITY") or e.get("WANDB_ENTITY") or default
|
|
95
|
+
|
|
96
|
+
@staticmethod
|
|
97
|
+
def is_debug(default: str | None = None, env: Mapping[str, str] | None = None) -> bool:
|
|
98
|
+
return False
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
env = _EnvNamespace()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def termwarn(msg: str, repeat: bool = True) -> None:
|
|
105
|
+
if not repeat and msg in _WARNED_NOOPS:
|
|
106
|
+
return
|
|
107
|
+
_WARNED_NOOPS.add(msg)
|
|
108
|
+
warnings.warn(f"[loglog] {msg}", RuntimeWarning, stacklevel=2)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def termlog(msg: str = "", newline: bool = True, repeat: bool = True) -> None:
|
|
112
|
+
if not repeat and msg in _WARNED_NOOPS:
|
|
113
|
+
return
|
|
114
|
+
_WARNED_NOOPS.add(msg)
|
|
115
|
+
sys.stderr.write(f"[loglog] {msg}" + ("\n" if newline else ""))
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def termerror(msg: str, repeat: bool = True) -> None:
|
|
119
|
+
sys.stderr.write(f"[loglog] ERROR: {msg}\n")
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _warn_noop(name: str) -> None:
|
|
123
|
+
if name not in _WARNED_NOOPS:
|
|
124
|
+
_WARNED_NOOPS.add(name)
|
|
125
|
+
warnings.warn(
|
|
126
|
+
f"[loglog] `{name}()` is a cloud-only W&B API and is a no-op in LogLog.",
|
|
127
|
+
RuntimeWarning,
|
|
128
|
+
stacklevel=3,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def login(
|
|
133
|
+
anonymous: str | None = None,
|
|
134
|
+
key: str | None = None,
|
|
135
|
+
relogin: bool | None = None,
|
|
136
|
+
host: str | None = None,
|
|
137
|
+
force: bool | None = None,
|
|
138
|
+
timeout: int | None = None,
|
|
139
|
+
verify: bool = False,
|
|
140
|
+
) -> bool:
|
|
141
|
+
"""Silent no-op returning True — LogLog is local-first and requires no API keys."""
|
|
142
|
+
return True
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _resolve_mode(explicit_mode: str | None) -> str:
|
|
146
|
+
if explicit_mode is not None:
|
|
147
|
+
return str(explicit_mode).strip().lower()
|
|
148
|
+
if os.environ.get("WANDB_DISABLED", "").strip().lower() in ("1", "true", "yes"):
|
|
149
|
+
return "disabled"
|
|
150
|
+
env_mode = os.environ.get("LOGLOG_MODE") or os.environ.get("WANDB_MODE")
|
|
151
|
+
if env_mode:
|
|
152
|
+
return env_mode.strip().lower()
|
|
153
|
+
return "local"
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _clear_active_run(finished_run: Run | DisabledRun) -> None:
|
|
157
|
+
global run
|
|
158
|
+
if run is finished_run:
|
|
159
|
+
run = None
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def init(
|
|
163
|
+
job_type: str | None = None,
|
|
164
|
+
dir: str | os.PathLike[str] | None = None,
|
|
165
|
+
config: Any = None,
|
|
166
|
+
project: str | None = None,
|
|
167
|
+
entity: str | None = None,
|
|
168
|
+
reinit: bool | str | None = None,
|
|
169
|
+
tags: Sequence[str] | None = None,
|
|
170
|
+
group: str | None = None,
|
|
171
|
+
name: str | None = None,
|
|
172
|
+
notes: str | None = None,
|
|
173
|
+
magic: bool | dict[str, Any] | None = None,
|
|
174
|
+
config_exclude_keys: Sequence[str] | None = None,
|
|
175
|
+
config_include_keys: Sequence[str] | None = None,
|
|
176
|
+
anonymous: str | None = None,
|
|
177
|
+
mode: str | None = None,
|
|
178
|
+
allow_val_change: bool | None = None,
|
|
179
|
+
resume: bool | str | None = None,
|
|
180
|
+
force: bool | None = None,
|
|
181
|
+
tensorboard: bool | None = None,
|
|
182
|
+
sync_tensorboard: bool | None = None,
|
|
183
|
+
monitor_gym: bool | None = None,
|
|
184
|
+
save_code: bool | None = True,
|
|
185
|
+
id: str | None = None,
|
|
186
|
+
fork_from: str | None = None,
|
|
187
|
+
resume_from: str | None = None,
|
|
188
|
+
settings: Settings | dict[str, Any] | None = None,
|
|
189
|
+
telemetry: bool | float | None = None,
|
|
190
|
+
**kwargs: Any,
|
|
191
|
+
) -> Run | DisabledRun:
|
|
192
|
+
"""Initialize a local LogLog run (drop-in replacement for `wandb.init`)."""
|
|
193
|
+
global run
|
|
194
|
+
if run is not None and reinit:
|
|
195
|
+
run.finish()
|
|
196
|
+
|
|
197
|
+
resolved_mode = _resolve_mode(mode)
|
|
198
|
+
if resolved_mode == "disabled":
|
|
199
|
+
new_run: Run | DisabledRun = DisabledRun(
|
|
200
|
+
project=project,
|
|
201
|
+
name=name,
|
|
202
|
+
id=id,
|
|
203
|
+
group=group,
|
|
204
|
+
job_type=job_type,
|
|
205
|
+
tags=tags,
|
|
206
|
+
notes=notes,
|
|
207
|
+
config=config,
|
|
208
|
+
dir=dir,
|
|
209
|
+
entity=entity,
|
|
210
|
+
)
|
|
211
|
+
run = new_run
|
|
212
|
+
return new_run
|
|
213
|
+
|
|
214
|
+
# Handle config_include_keys / config_exclude_keys if supplied
|
|
215
|
+
cfg = config
|
|
216
|
+
if cfg is not None and (config_include_keys or config_exclude_keys):
|
|
217
|
+
from loglog.sdk.config import coerce_config_mapping
|
|
218
|
+
|
|
219
|
+
d = coerce_config_mapping(cfg)
|
|
220
|
+
if config_include_keys:
|
|
221
|
+
inc = set(config_include_keys)
|
|
222
|
+
d = {k: v for k, v in d.items() if k in inc}
|
|
223
|
+
if config_exclude_keys:
|
|
224
|
+
exc = set(config_exclude_keys)
|
|
225
|
+
d = {k: v for k, v in d.items() if k not in exc}
|
|
226
|
+
cfg = d
|
|
227
|
+
|
|
228
|
+
env_tags = os.environ.get("LOGLOG_TAGS") or os.environ.get("WANDB_TAGS")
|
|
229
|
+
resolved_tags = list(tags) if tags is not None else ([t.strip() for t in env_tags.split(",") if t.strip()] if env_tags else [])
|
|
230
|
+
|
|
231
|
+
new_run = Run(
|
|
232
|
+
project=project,
|
|
233
|
+
name=name,
|
|
234
|
+
id=id,
|
|
235
|
+
group=group,
|
|
236
|
+
job_type=job_type,
|
|
237
|
+
tags=resolved_tags,
|
|
238
|
+
notes=notes,
|
|
239
|
+
config=cfg,
|
|
240
|
+
dir=dir,
|
|
241
|
+
entity=entity,
|
|
242
|
+
mode=resolved_mode,
|
|
243
|
+
resume=resume,
|
|
244
|
+
save_code=save_code,
|
|
245
|
+
sync_tensorboard=bool(sync_tensorboard or tensorboard),
|
|
246
|
+
telemetry=telemetry,
|
|
247
|
+
on_finish=_clear_active_run,
|
|
248
|
+
)
|
|
249
|
+
run = new_run
|
|
250
|
+
return new_run
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def finish(exit_code: int | None = 0, quiet: bool | None = None) -> None:
|
|
254
|
+
global run
|
|
255
|
+
if run is not None:
|
|
256
|
+
r = run
|
|
257
|
+
run = None
|
|
258
|
+
r.finish(exit_code=exit_code, quiet=quiet)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def log(
|
|
262
|
+
data: Mapping[str, Any],
|
|
263
|
+
step: int | None = None,
|
|
264
|
+
commit: bool | None = None,
|
|
265
|
+
sync: bool | None = None,
|
|
266
|
+
) -> None:
|
|
267
|
+
if run is None:
|
|
268
|
+
raise RuntimeError("You must call loglog.init() before loglog.log()")
|
|
269
|
+
run.log(data, step=step, commit=commit, sync=sync)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def define_metric(
|
|
273
|
+
name: str,
|
|
274
|
+
step_metric: str | None = None,
|
|
275
|
+
step_sync: bool | None = None,
|
|
276
|
+
hidden: bool | None = None,
|
|
277
|
+
summary: str | None = None,
|
|
278
|
+
goal: str | None = None,
|
|
279
|
+
overwrite: bool | None = None,
|
|
280
|
+
) -> dict[str, Any]:
|
|
281
|
+
if run is None:
|
|
282
|
+
return {"name": name, "step_metric": step_metric, "summary": summary}
|
|
283
|
+
return run.define_metric(
|
|
284
|
+
name=name,
|
|
285
|
+
step_metric=step_metric,
|
|
286
|
+
step_sync=step_sync,
|
|
287
|
+
hidden=hidden,
|
|
288
|
+
summary=summary,
|
|
289
|
+
goal=goal,
|
|
290
|
+
overwrite=overwrite,
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def log_artifact(
|
|
295
|
+
artifact_or_path: Artifact | str | os.PathLike[str],
|
|
296
|
+
name: str | None = None,
|
|
297
|
+
type: str | None = None,
|
|
298
|
+
aliases: Sequence[str] | None = None,
|
|
299
|
+
tags: Sequence[str] | None = None,
|
|
300
|
+
) -> Artifact:
|
|
301
|
+
if run is None:
|
|
302
|
+
raise RuntimeError("You must call loglog.init() before loglog.log_artifact()")
|
|
303
|
+
return run.log_artifact(artifact_or_path, name=name, type=type, aliases=aliases, tags=tags)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def use_artifact(
|
|
307
|
+
artifact_or_name: Artifact | str,
|
|
308
|
+
type: str | None = None,
|
|
309
|
+
aliases: Sequence[str] | None = None,
|
|
310
|
+
use_as: str | None = None,
|
|
311
|
+
) -> Artifact:
|
|
312
|
+
if run is None:
|
|
313
|
+
raise RuntimeError("You must call loglog.init() before loglog.use_artifact()")
|
|
314
|
+
return run.use_artifact(artifact_or_name, type=type, aliases=aliases, use_as=use_as)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def save(
|
|
318
|
+
glob_str: str | os.PathLike[str] | None = None,
|
|
319
|
+
base_path: str | os.PathLike[str] | None = None,
|
|
320
|
+
policy: str = "live",
|
|
321
|
+
) -> list[str]:
|
|
322
|
+
if run is None:
|
|
323
|
+
return []
|
|
324
|
+
return run.save(glob_str=glob_str, base_path=base_path, policy=policy)
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def alert(
|
|
328
|
+
title: str,
|
|
329
|
+
text: str,
|
|
330
|
+
level: AlertLevel | str | None = None,
|
|
331
|
+
wait_duration: int = 300,
|
|
332
|
+
) -> None:
|
|
333
|
+
if run is None:
|
|
334
|
+
return
|
|
335
|
+
run.alert(title=title, text=text, level=level, wait_duration=wait_duration)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def watch(
|
|
339
|
+
models: Any,
|
|
340
|
+
criterion: Any = None,
|
|
341
|
+
log: str | None = "gradients",
|
|
342
|
+
log_freq: int = 1000,
|
|
343
|
+
idx: int | None = None,
|
|
344
|
+
log_graph: bool = False,
|
|
345
|
+
log_freq_override: bool = False,
|
|
346
|
+
) -> None:
|
|
347
|
+
if run is not None:
|
|
348
|
+
run.watch(
|
|
349
|
+
models,
|
|
350
|
+
criterion=criterion,
|
|
351
|
+
log=log,
|
|
352
|
+
log_freq=log_freq,
|
|
353
|
+
idx=idx,
|
|
354
|
+
log_graph=log_graph,
|
|
355
|
+
log_freq_override=log_freq_override,
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def unwatch(models: Any = None) -> None:
|
|
360
|
+
if run is not None:
|
|
361
|
+
run.unwatch(models)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def mark_preempting() -> None:
|
|
365
|
+
if run is not None:
|
|
366
|
+
run.mark_preempting()
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
# Graceful cloud-only no-ops
|
|
370
|
+
def sweep(*args: Any, **kwargs: Any) -> str:
|
|
371
|
+
_warn_noop("sweep")
|
|
372
|
+
return "local-sweep-noop"
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def agent(*args: Any, **kwargs: Any) -> None:
|
|
376
|
+
_warn_noop("agent")
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def controller(*args: Any, **kwargs: Any) -> None:
|
|
380
|
+
_warn_noop("controller")
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def require(*args: Any, **kwargs: Any) -> None:
|
|
384
|
+
_warn_noop("require")
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def teardown(exit_code: int | None = None) -> None:
|
|
388
|
+
_warn_noop("teardown")
|
|
389
|
+
if run is not None:
|
|
390
|
+
finish(exit_code=exit_code)
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def join(exit_code: int | None = None) -> None:
|
|
394
|
+
finish(exit_code=exit_code)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def setup(settings: Any = None) -> None:
|
|
398
|
+
return
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
class _ConfigUtilShim:
|
|
402
|
+
@staticmethod
|
|
403
|
+
def dict_from_config_file(path: str) -> dict[str, Any]:
|
|
404
|
+
from pathlib import Path
|
|
405
|
+
|
|
406
|
+
from loglog.storage.layout import read_json_safe
|
|
407
|
+
|
|
408
|
+
return read_json_safe(Path(path), {}) or {}
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def shim_wandb(set_dummy_api_key: bool = True) -> None:
|
|
412
|
+
"""Register LogLog as `sys.modules['wandb']` so unmodified W&B/HF/Lightning scripts log to LogLog.
|
|
413
|
+
|
|
414
|
+
When `set_dummy_api_key=True` and `WANDB_API_KEY` is unset, sets a local placeholder
|
|
415
|
+
so scripts that gate on `if os.getenv('WANDB_API_KEY'):` run cleanly without a real key.
|
|
416
|
+
"""
|
|
417
|
+
mod = sys.modules[__name__]
|
|
418
|
+
sys.modules["wandb"] = mod
|
|
419
|
+
|
|
420
|
+
# Register commonly imported wandb submodules used by HF Transformers, Accelerate, Lightning
|
|
421
|
+
submodules: dict[str, dict[str, Any]] = {
|
|
422
|
+
"wandb.env": {k: getattr(env, k) for k in dir(env) if not k.startswith("_")},
|
|
423
|
+
"wandb.plot": {k: getattr(plot, k) for k in dir(plot) if not k.startswith("_")},
|
|
424
|
+
"wandb.errors": {"Error": RuntimeError, "CommError": RuntimeError, "UsageError": ValueError},
|
|
425
|
+
"wandb.sdk": {"wandb_run": types.SimpleNamespace(Run=Run)},
|
|
426
|
+
"wandb.sdk.lib": {"config_util": _ConfigUtilShim},
|
|
427
|
+
"wandb.sdk.lib.config_util": {"dict_from_config_file": _ConfigUtilShim.dict_from_config_file},
|
|
428
|
+
"wandb.apis": {"public": types.SimpleNamespace(Api=Api, Run=ApiRun)},
|
|
429
|
+
"wandb.apis.public": {"Api": Api, "Run": ApiRun},
|
|
430
|
+
}
|
|
431
|
+
for mod_name, attrs in submodules.items():
|
|
432
|
+
m = types.ModuleType(mod_name)
|
|
433
|
+
for k, v in attrs.items():
|
|
434
|
+
setattr(m, k, v)
|
|
435
|
+
sys.modules[mod_name] = m
|
|
436
|
+
|
|
437
|
+
if set_dummy_api_key and not os.environ.get("WANDB_API_KEY"):
|
|
438
|
+
os.environ["WANDB_API_KEY"] = "loglog-local"
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
__all__ = [
|
|
442
|
+
"__version__",
|
|
443
|
+
"AlertLevel",
|
|
444
|
+
"Api",
|
|
445
|
+
"ApiRun",
|
|
446
|
+
"Artifact",
|
|
447
|
+
"Config",
|
|
448
|
+
"CustomChart",
|
|
449
|
+
"DisabledRun",
|
|
450
|
+
"Histogram",
|
|
451
|
+
"Html",
|
|
452
|
+
"Image",
|
|
453
|
+
"Run",
|
|
454
|
+
"Settings",
|
|
455
|
+
"Summary",
|
|
456
|
+
"Table",
|
|
457
|
+
"agent",
|
|
458
|
+
"alert",
|
|
459
|
+
"config",
|
|
460
|
+
"controller",
|
|
461
|
+
"define_metric",
|
|
462
|
+
"env",
|
|
463
|
+
"finish",
|
|
464
|
+
"init",
|
|
465
|
+
"join",
|
|
466
|
+
"log",
|
|
467
|
+
"log_artifact",
|
|
468
|
+
"login",
|
|
469
|
+
"mark_preempting",
|
|
470
|
+
"plot",
|
|
471
|
+
"require",
|
|
472
|
+
"run",
|
|
473
|
+
"save",
|
|
474
|
+
"setup",
|
|
475
|
+
"shim_wandb",
|
|
476
|
+
"summary",
|
|
477
|
+
"sweep",
|
|
478
|
+
"teardown",
|
|
479
|
+
"termerror",
|
|
480
|
+
"termlog",
|
|
481
|
+
"termwarn",
|
|
482
|
+
"unwatch",
|
|
483
|
+
"use_artifact",
|
|
484
|
+
"watch",
|
|
485
|
+
]
|
loglog/cli.py
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"""LogLog command-line interface: `serve`, `run`, `freeze`, `ls`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import tempfile
|
|
12
|
+
import webbrowser
|
|
13
|
+
from collections.abc import Sequence
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
_WANDB_SHIM_PY = '''"""Auto-generated LogLog W&B shim module."""
|
|
17
|
+
import loglog as _ll
|
|
18
|
+
_ll.shim_wandb(set_dummy_api_key=True)
|
|
19
|
+
from loglog import * # noqa: F401,F403
|
|
20
|
+
__version__ = _ll.__version__
|
|
21
|
+
'''
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _default_roots(paths: Sequence[str]) -> list[Path]:
|
|
25
|
+
if paths:
|
|
26
|
+
return [Path(p).expanduser().resolve() for p in paths]
|
|
27
|
+
cwd = Path.cwd()
|
|
28
|
+
if (cwd / ".loglog").is_dir():
|
|
29
|
+
return [cwd / ".loglog"]
|
|
30
|
+
return [cwd]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _cmd_serve(args: argparse.Namespace) -> int:
|
|
34
|
+
import uvicorn
|
|
35
|
+
|
|
36
|
+
from loglog.server.app import create_app
|
|
37
|
+
|
|
38
|
+
roots = _default_roots(args.paths)
|
|
39
|
+
app = create_app(roots=roots, state_dir=args.state_dir)
|
|
40
|
+
url = f"http://{args.host}:{args.port}"
|
|
41
|
+
print(f"LogLog serving {len(roots)} path(s) on {url}")
|
|
42
|
+
for r in roots:
|
|
43
|
+
print(f" - {r}")
|
|
44
|
+
if args.open:
|
|
45
|
+
try:
|
|
46
|
+
webbrowser.open(url)
|
|
47
|
+
except Exception:
|
|
48
|
+
pass
|
|
49
|
+
uvicorn.run(app, host=args.host, port=args.port, log_level="warning" if args.quiet else "info")
|
|
50
|
+
return 0
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _cmd_run(args: argparse.Namespace) -> int:
|
|
54
|
+
cmd = list(args.command)
|
|
55
|
+
if cmd and cmd[0] == "--":
|
|
56
|
+
cmd = cmd[1:]
|
|
57
|
+
if not cmd:
|
|
58
|
+
print("Error: provide a command after `--`, e.g. `loglog run --shim-wandb -- python train.py`", file=sys.stderr)
|
|
59
|
+
return 2
|
|
60
|
+
|
|
61
|
+
env = os.environ.copy()
|
|
62
|
+
if args.project:
|
|
63
|
+
env["LOGLOG_PROJECT"] = args.project
|
|
64
|
+
env["WANDB_PROJECT"] = args.project
|
|
65
|
+
if args.name:
|
|
66
|
+
env["LOGLOG_NAME"] = args.name
|
|
67
|
+
env["WANDB_NAME"] = args.name
|
|
68
|
+
if args.group:
|
|
69
|
+
env["LOGLOG_RUN_GROUP"] = args.group
|
|
70
|
+
env["WANDB_RUN_GROUP"] = args.group
|
|
71
|
+
if args.dir:
|
|
72
|
+
env["LOGLOG_DIR"] = str(Path(args.dir).expanduser().resolve())
|
|
73
|
+
env["WANDB_DIR"] = env["LOGLOG_DIR"]
|
|
74
|
+
if args.telemetry:
|
|
75
|
+
env["LOGLOG_TELEMETRY"] = "1"
|
|
76
|
+
if args.save_untracked:
|
|
77
|
+
env["LOGLOG_SAVE_UNTRACKED"] = "1"
|
|
78
|
+
|
|
79
|
+
shim_dir: str | None = None
|
|
80
|
+
try:
|
|
81
|
+
if args.shim_wandb:
|
|
82
|
+
shim_dir = tempfile.mkdtemp(prefix="loglog-wandb-shim-")
|
|
83
|
+
Path(shim_dir, "wandb.py").write_text(_WANDB_SHIM_PY, encoding="utf-8")
|
|
84
|
+
prev_pp = env.get("PYTHONPATH", "")
|
|
85
|
+
env["PYTHONPATH"] = f"{shim_dir}{os.pathsep}{prev_pp}" if prev_pp else shim_dir
|
|
86
|
+
if not env.get("WANDB_API_KEY"):
|
|
87
|
+
env["WANDB_API_KEY"] = "loglog-local"
|
|
88
|
+
|
|
89
|
+
proc = subprocess.run(cmd, env=env)
|
|
90
|
+
return int(proc.returncode)
|
|
91
|
+
finally:
|
|
92
|
+
if shim_dir is not None:
|
|
93
|
+
shutil.rmtree(shim_dir, ignore_errors=True)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _cmd_freeze(args: argparse.Namespace) -> int:
|
|
97
|
+
from loglog.storage.reports import freeze_report
|
|
98
|
+
from loglog.storage.scanner import RunStore
|
|
99
|
+
|
|
100
|
+
roots = _default_roots(args.paths)
|
|
101
|
+
store = RunStore(roots=roots, state_dir=args.state_dir)
|
|
102
|
+
|
|
103
|
+
markdown = args.markdown or ""
|
|
104
|
+
if args.markdown_file:
|
|
105
|
+
markdown = Path(args.markdown_file).expanduser().read_text(encoding="utf-8")
|
|
106
|
+
|
|
107
|
+
run_keys = [x.strip() for x in args.runs.split(",") if x.strip()] if args.runs else None
|
|
108
|
+
view_settings: dict[str, object] = {}
|
|
109
|
+
if args.baseline:
|
|
110
|
+
view_settings["baselineRunKey"] = args.baseline
|
|
111
|
+
if args.x_mode:
|
|
112
|
+
view_settings["xMode"] = args.x_mode
|
|
113
|
+
if args.x_metric:
|
|
114
|
+
view_settings["xMetric"] = args.x_metric
|
|
115
|
+
|
|
116
|
+
res = freeze_report(
|
|
117
|
+
store,
|
|
118
|
+
title=args.title,
|
|
119
|
+
description=args.description or "",
|
|
120
|
+
markdown=markdown,
|
|
121
|
+
run_keys=run_keys,
|
|
122
|
+
view_settings=view_settings or None,
|
|
123
|
+
max_step=args.max_step,
|
|
124
|
+
output_html_path=Path(args.output) if args.output else None,
|
|
125
|
+
)
|
|
126
|
+
print(f"Frozen report {res['hash']} ({res['html_bytes'] / 1024:.1f} KiB)")
|
|
127
|
+
print(f" Bundle: {res['report_dir']}")
|
|
128
|
+
print(f" HTML: {args.output or res['html_path']}")
|
|
129
|
+
print(f" Permalink: {res['permalink']} (when running `loglog serve`)")
|
|
130
|
+
return 0
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _cmd_ls(args: argparse.Namespace) -> int:
|
|
134
|
+
from loglog.storage.scanner import RunStore
|
|
135
|
+
|
|
136
|
+
roots = _default_roots(args.paths)
|
|
137
|
+
store = RunStore(roots=roots, state_dir=args.state_dir)
|
|
138
|
+
runs = store.list_runs_metadata(refresh=False)
|
|
139
|
+
if args.json:
|
|
140
|
+
print(json.dumps(runs, indent=2))
|
|
141
|
+
return 0
|
|
142
|
+
if not runs:
|
|
143
|
+
print("No LogLog or TensorBoard runs found.")
|
|
144
|
+
return 0
|
|
145
|
+
header = f"{'SOURCE':<9} {'STATUS':<10} {'PROJECT':<18} {'NAME':<26} {'STEP':>8} {'KEY SUMMARY'}"
|
|
146
|
+
print(header)
|
|
147
|
+
print("-" * len(header))
|
|
148
|
+
for r in runs:
|
|
149
|
+
summ = r.get("summary") or {}
|
|
150
|
+
highlights = []
|
|
151
|
+
for k in ("eval/loss", "eval/accuracy", "train/step_loss", "train/loss"):
|
|
152
|
+
if k in summ and isinstance(summ[k], (int, float)):
|
|
153
|
+
highlights.append(f"{k}={summ[k]:.4g}")
|
|
154
|
+
if not highlights:
|
|
155
|
+
for k, v in list(summ.items())[:3]:
|
|
156
|
+
if isinstance(v, (int, float)):
|
|
157
|
+
highlights.append(f"{k}={v:.4g}")
|
|
158
|
+
print(
|
|
159
|
+
f"{r['source']:<9} {r['status']:<10} {r['project'][:18]:<18} "
|
|
160
|
+
f"{r['name'][:26]:<26} {int(r['last_step']):>8} {', '.join(highlights)}"
|
|
161
|
+
)
|
|
162
|
+
return 0
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
166
|
+
parser = argparse.ArgumentParser(
|
|
167
|
+
prog="loglog",
|
|
168
|
+
description="LogLog — lightweight local-first W&B drop-in & TensorBoard dashboard.",
|
|
169
|
+
)
|
|
170
|
+
sub = parser.add_subparsers(dest="subcommand", required=True)
|
|
171
|
+
|
|
172
|
+
# serve
|
|
173
|
+
p_serve = sub.add_parser("serve", help="Serve interactive dashboard for .loglog/ and tfevents directories")
|
|
174
|
+
p_serve.add_argument("paths", nargs="*", help="One or more directories containing .loglog/ or tfevents runs")
|
|
175
|
+
p_serve.add_argument("--host", default="127.0.0.1", help="Bind address (default: 127.0.0.1)")
|
|
176
|
+
p_serve.add_argument("-p", "--port", type=int, default=6060, help="Port (default: 6060)")
|
|
177
|
+
p_serve.add_argument("--state-dir", default=None, help="Directory for SQLite index and frozen reports")
|
|
178
|
+
p_serve.add_argument("--open", action="store_true", help="Open browser automatically")
|
|
179
|
+
p_serve.add_argument("-q", "--quiet", action="store_true", help="Reduce uvicorn access logs")
|
|
180
|
+
p_serve.set_defaults(func=_cmd_serve)
|
|
181
|
+
|
|
182
|
+
# run
|
|
183
|
+
p_run = sub.add_parser("run", help="Run a training command with LogLog environment & optional W&B shim")
|
|
184
|
+
p_run.add_argument("--shim-wandb", action="store_true", help="Intercept `import wandb` and route to LogLog")
|
|
185
|
+
p_run.add_argument("--project", default=None, help="Override LOGLOG_PROJECT / WANDB_PROJECT")
|
|
186
|
+
p_run.add_argument("--name", default=None, help="Override LOGLOG_NAME / WANDB_NAME")
|
|
187
|
+
p_run.add_argument("--group", default=None, help="Override LOGLOG_RUN_GROUP / WANDB_RUN_GROUP")
|
|
188
|
+
p_run.add_argument("--dir", default=None, help="Override LOGLOG_DIR / WANDB_DIR")
|
|
189
|
+
p_run.add_argument("--telemetry", action="store_true", help="Enable background GPU/CPU system telemetry")
|
|
190
|
+
p_run.add_argument("--save-untracked", action="store_true", help="Include untracked source files in code.patch")
|
|
191
|
+
p_run.add_argument("command", nargs=argparse.REMAINDER, help="Command to execute (prefix with `--`)")
|
|
192
|
+
p_run.set_defaults(func=_cmd_run)
|
|
193
|
+
|
|
194
|
+
# freeze
|
|
195
|
+
p_freeze = sub.add_parser("freeze", help="Freeze an immutable snapshot report + standalone .html")
|
|
196
|
+
p_freeze.add_argument("paths", nargs="*", help="Directories containing runs")
|
|
197
|
+
p_freeze.add_argument("--title", required=True, help="Report title")
|
|
198
|
+
p_freeze.add_argument("--description", default="", help="Short subtitle/description")
|
|
199
|
+
p_freeze.add_argument("--markdown", default="", help="Inline Markdown narrative")
|
|
200
|
+
p_freeze.add_argument("--markdown-file", default=None, help="Path to Markdown narrative file")
|
|
201
|
+
p_freeze.add_argument("--runs", default=None, help="Comma-separated run keys, IDs, or names to include")
|
|
202
|
+
p_freeze.add_argument("--baseline", default=None, help="Pinned baseline run key for Delta panels")
|
|
203
|
+
p_freeze.add_argument("--max-step", type=int, default=None, help="Freeze metrics at <= max_step")
|
|
204
|
+
p_freeze.add_argument("--x-mode", choices=["step", "tokens", "wall", "metric"], default=None)
|
|
205
|
+
p_freeze.add_argument("--x-metric", default=None, help="Metric name to use as X-axis")
|
|
206
|
+
p_freeze.add_argument("-o", "--output", default=None, help="Write standalone .html copy to this path")
|
|
207
|
+
p_freeze.add_argument("--state-dir", default=None, help="Directory for index and reports store")
|
|
208
|
+
p_freeze.set_defaults(func=_cmd_freeze)
|
|
209
|
+
|
|
210
|
+
# ls
|
|
211
|
+
p_ls = sub.add_parser("ls", help="List discovered LogLog and TensorBoard runs")
|
|
212
|
+
p_ls.add_argument("paths", nargs="*", help="Directories to scan")
|
|
213
|
+
p_ls.add_argument("--state-dir", default=None)
|
|
214
|
+
p_ls.add_argument("--json", action="store_true", help="Output raw JSON")
|
|
215
|
+
p_ls.set_defaults(func=_cmd_ls)
|
|
216
|
+
|
|
217
|
+
return parser
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
221
|
+
parser = build_parser()
|
|
222
|
+
args = parser.parse_args(argv)
|
|
223
|
+
return int(args.func(args))
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
if __name__ == "__main__":
|
|
227
|
+
raise SystemExit(main())
|