feat: add SelVA TI Scheduler for sweep-based textual inversion experiments
- SelvaTiScheduler: runs a JSON-defined sweep of TI training experiments,
loading the dataset once and reusing it across runs
- Collects per-experiment loss history, final/min loss, stability metric
(loss_std_last_quarter), and duration — written to experiment_summary.json
after each completed run so partial sweeps survive interruption
- Resume-aware: skips experiments already marked completed in an existing
summary file
- Outputs smoothed loss comparison chart (same axes, one curve per experiment)
- SelvaTextualInversionTrainer._train_inner now returns a dict
{embeddings_path, loss_history} so the scheduler can read results;
train() extracts just the path for ComfyUI
JSON format: name, description, data_dir, output_root, base config,
experiments list with id + param overrides
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -201,13 +201,14 @@ class SelvaTextualInversionTrainer:
|
||||
|
||||
# Training must run outside inference_mode so autograd works
|
||||
with torch.inference_mode(False), torch.enable_grad():
|
||||
return self._train_inner(
|
||||
r = self._train_inner(
|
||||
model, dataset, feature_utils_orig, seq_cfg,
|
||||
device, dtype, mode,
|
||||
data_dir, out_path,
|
||||
n_tokens, steps, lr, batch_size,
|
||||
warmup_steps, seed, save_every, init_text,
|
||||
)
|
||||
return (r["embeddings_path"],)
|
||||
|
||||
def _train_inner(
|
||||
self, model, dataset, feature_utils_orig, seq_cfg,
|
||||
@@ -368,4 +369,7 @@ class SelvaTextualInversionTrainer:
|
||||
print(f"\n[TI Trainer] Done. Saved: {out_path}", flush=True)
|
||||
|
||||
soft_empty_cache()
|
||||
return (str(out_path),)
|
||||
return {
|
||||
"embeddings_path": str(out_path),
|
||||
"loss_history": loss_history,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user