adaptcompile
adaptcompile is a model-agnostic Python library for representing, measuring,
predicting, selecting, and executing model adaptations through pluggable backends.
adaptcompile treats model adaptation as a behavioral transformation that can be
represented, measured, predicted, selected, and handed to a user-supplied execution
backend independently of any training framework.
See the architecture overview for how the objects fit together.
Installation
pip install adaptcompile
DataFrame exports are optional:
pip install "adaptcompile[dataframe]"
The reference prediction implementation is also optional:
pip install "adaptcompile[predict]"
For contributor setup:
python -m pip install -e ".[dev]"
Minimal example
from adaptcompile import (
AdaptationResult,
AdaptationStudy,
LearningEpisode,
ModelContext,
ProgramSpec,
)
model = ModelContext("example/model", revision="v1", base_state_id="base-1")
episode = LearningEpisode(
"toy-task",
train=["example"],
evaluations={"accuracy": ["held-out example"]},
episode_id="toy-task-v1",
)
results = [
AdaptationResult(
model_context=model,
episode=episode,
program=ProgramSpec(name, "adapter", {"strength": strength}),
before={"accuracy": 0.40},
after={"accuracy": score},
)
for name, strength, score in [
("gentle", 0.25, 0.68),
("strong", 0.75, 0.81),
]
]
study = AdaptationStudy(results)
print(study.best("accuracy").program.name)
print(study.best("accuracy").delta.to_dict())
More runnable examples are available in examples.
Core objects
ModelContextidentifies a model revision and pre-adaptation base state.LearningEpisodenames a learning problem and references its datasets.ProgramFamilydescribes a conceptual adaptation family.ProgramSpecdeclares one concrete, backend-independent adaptation program.AdaptationGeometrystores arbitrary-dimensional behavioral measurements.AdaptationResultrecords before/after geometry for one observed adaptation.AdaptationStudycompares programs for one fixed model context and episode.AdaptationDatasetstores observations across models, episodes, and programs.
Public records support JSON-safe serialization. Dataset-like objects attached to a
LearningEpisode are intentionally held by reference and are not serialized.
DataFrame export is available through the optional dataframe extra.
Compiler-ready data
adaptcompile.compiler combines an AdaptationDataset with externally supplied
numeric decision-time descriptors to produce a validated supervised dataset.
Feature extraction remains external. Version 0.3 can fit a predictor over the
assembled numeric features.
from adaptcompile.compiler import build_compiler_dataset
compiler_data = build_compiler_dataset(
observations,
episode_descriptors=episode_features,
program_descriptors=program_features,
target="delta",
)
print(compiler_data.feature_names)
See the compiler data contract for descriptor identities, namespaces, baseline features, and validation rules.
Predicting geometry
The dependency-free GeometryPredictor protocol defines target-free prediction from
compiler features and candidate identity. RidgeGeometryPredictor is one optional,
deliberately simple reference implementation:
from adaptcompile.compiler.predictors import RidgeGeometryPredictor
predictor = RidgeGeometryPredictor().fit(compiler_data)
prediction = predictor.predict(
features=compiler_data[0].features,
model_key=compiler_data[0].model_key,
episode_key=compiler_data[0].episode_key,
family_fingerprint=compiler_data[0].family_fingerprint,
program_fingerprint=compiler_data[0].program_fingerprint,
)
print(prediction.predicted_geometry)
See prediction for target semantics and delta reconstruction.
Selecting a program
Selection uses predicted post-adaptation geometry, an explicit weighted objective, and optional hard constraints:
from adaptcompile.compiler import GeometryConstraint, SelectionObjective
from adaptcompile.compiler.selectors import LinearUtilitySelector
objective = SelectionObjective(
maximize={"gain": 1.0},
minimize={"cost": 0.2},
constraints=(GeometryConstraint("retention", minimum=0.8),),
)
selection = LinearUtilitySelector().select(predictions, objective)
See selection for ranking, feasibility, and tie semantics.
Executing a selection
Execution resolves the selected fingerprint against explicit concrete programs and
delegates the matching ProgramSpec to a user-supplied backend:
from adaptcompile.execution import execute_selection
from adaptcompile.execution.backends import CallableBackend
outcome = execute_selection(
selection,
programs=programs,
model=model,
model_context=model_context,
episode=episode,
backend=CallableBackend(handler, backend_id="custom"),
)
See execution for program resolution, provenance, mutation, and framework-boundary semantics.
What adaptcompile does not do
- It does not implement model training or model loading.
- It does not implement LoRA or replace PEFT, TRL, or another training framework.
- It does not infer objectives, synthesize programs, evaluate adaptations, or interpret program parameters in the core package.
- It has no mandatory ML-framework or numerical-stack dependencies; pandas and the scikit-learn reference predictor are optional extras.
Status
0.5.0 adds selected-program resolution and pluggable execution. The API is usable
but may evolve during the 0.x series. Execution is delegated to user-supplied
backends; the core package remains framework-agnostic and does not evaluate outcomes.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adaptcompile-0.5.0.tar.gz.
File metadata
- Download URL: adaptcompile-0.5.0.tar.gz
- Upload date:
- Size: 64.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acfb6142258f9ae31d00a2bcf3291dc02d9097646f70d84aeb8f0932821d6735
|
|
| MD5 |
3af8ab4803932e026bd648700427bdee
|
|
| BLAKE2b-256 |
da30b7c168eb548b2fb4a73b7ad7e406474744dcbf47b75946e6c7042a778569
|
File details
Details for the file adaptcompile-0.5.0-py3-none-any.whl.
File metadata
- Download URL: adaptcompile-0.5.0-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cff74169d9236a3ed599840e741d4f2623e6ebe0ba7b006a67736810b779bff
|
|
| MD5 |
089fa35f4eebc5c0f53a5e670fe69177
|
|
| BLAKE2b-256 |
3cc96169af8e0f3469a5bfe6d58e1dcef6e209bf7babc0ba9309845fbeeac678
|