17. Adapter Management

Chapter 17 of 24 · 20 min

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

: Implement Adapter Versioning

Create a system that tracks adapter lineage—learning which adapters influenced which others:

class VersionedAdapter:
    def __init__(self, base_model_id, adapter_id, version, parent_ids=None):
        self.base_model_id = base_model_id
        self.adapter_id = adapter_id
        self.version = version
        self.parent_ids = parent_ids or []
    
    def save(self, path):
        metadata = {
            "base_model_id": self.base_model_id,
            "adapter_id": self.adapter_id,
            "version": self.version,
            "parent_ids": self.parent_ids
        }
        with open(Path(path) / "version_info.json", "w") as f:
            json.dump(metadata, f)
    
    @classmethod
    def load(cls, path):
        with open(Path(path) / "version_info.json") as f:
            metadata = json.load(f)
        return cls(**metadata)