Programmatic Quickstart

Overview

AspectDetails
PurposeMinimal Python example for running InvarLock without the CLI.
AudienceDevelopers running small scripted experiments.
Supported surfaceCoreRunner.execute and adapters/guards/edits from core packages.
Requiresinvarlock[adapters] for HF adapters; invarlock[edits] for built-in edits; invarlock[guards] for guard math.
NetworkOffline by default; set INVARLOCK_ALLOW_NETWORK=1 for downloads.

Quick Start

from invarlock.adapters import HF_Auto_Adapter
from invarlock.core.api import RunConfig
from invarlock.core.runner import CoreRunner
from invarlock.edits import RTNQuantEdit
from invarlock.guards import InvariantsGuard

adapter = HF_Auto_Adapter()
model = adapter.load_model("gpt2", device="auto")

edit = RTNQuantEdit(bitwidth=8, per_channel=True, group_size=128, clamp_ratio=0.005)
guards = [InvariantsGuard()]

config = RunConfig(device="auto")
report = CoreRunner().execute(model, adapter, edit, guards, config)

print("status:", report.status)

Concepts

  • Prefer the CLI for full workflows (pairing, reports, reproducibility).
  • Programmatic runs still follow the same pipeline phases and produce a RunReport object.
  • Pass calibration_data to CoreRunner.execute for real primary-metric values.
  • Enable downloads per run with INVARLOCK_ALLOW_NETWORK=1 when using remote model IDs.

Reference

Troubleshooting

  • Dependency missing: install invarlock[adapters] or invarlock[guards].
  • Downloads blocked: use INVARLOCK_ALLOW_NETWORK=1 for HF downloads.

Observability

  • Inspect report.meta, report.guards, and report.metrics.
  • For report generation, use invarlock.reporting.report_builder.make_report.