Registry
The registry module provides decorator-based plugin registration.
Use these decorators for new methods:
@register_probe("name")@register_monitor("name")@register_attributor("name")
The pipeline runner calls create_probe, create_monitor, and
create_attributor to instantiate methods from YAML.
Minimal example:
from collections.abc import Sequence
from typing import Any
from SafeLens.core.base import BaseProbe, Batch, ModelWrapper, ProbeResult
from SafeLens.core.registry import create_probe, register_probe
@register_probe("constant_probe")
class ConstantProbe(BaseProbe):
def attach(self, model: ModelWrapper, layers: Sequence[int]) -> None:
pass
def detect(self, batch: Batch) -> ProbeResult:
return ProbeResult(risk_score=0.0, critical_layers=[])
def intervene(self, batch: Batch, direction: Any, scale: float) -> None:
pass
def detach(self) -> None:
pass
probe = create_probe("constant_probe")
Decorator-based registries for pluggable SafeLens methods.
RegistryError
Bases: KeyError
Raised when a method registry lookup or registration fails.
Source code in src/SafeLens/core/registry.py
20 21 | |
create_attributor(name, config=None)
Instantiate a registered attributor.
Source code in src/SafeLens/core/registry.py
104 105 106 | |
create_monitor(name, config=None)
Instantiate a registered monitor.
Source code in src/SafeLens/core/registry.py
99 100 101 | |
create_probe(name, config=None)
Instantiate a registered probe.
Source code in src/SafeLens/core/registry.py
94 95 96 | |
get_attributor(name)
Return a registered attributor class.
Source code in src/SafeLens/core/registry.py
86 87 88 89 90 91 | |
get_monitor(name)
Return a registered monitor class.
Source code in src/SafeLens/core/registry.py
78 79 80 81 82 83 | |
get_probe(name)
Return a registered probe class.
Source code in src/SafeLens/core/registry.py
70 71 72 73 74 75 | |
list_attributors()
List registered attributor names.
Source code in src/SafeLens/core/registry.py
119 120 121 | |
list_monitors()
List registered monitor names.
Source code in src/SafeLens/core/registry.py
114 115 116 | |
list_probes()
List registered probe names.
Source code in src/SafeLens/core/registry.py
109 110 111 | |
load_builtin_methods()
Import built-in plugins so their registration decorators run.
Source code in src/SafeLens/core/registry.py
24 25 26 27 28 29 30 31 | |
register_attributor(name, replace=False)
Register an attributor class by name.
Source code in src/SafeLens/core/registry.py
65 66 67 | |
register_monitor(name, replace=False)
Register a monitor class by name.
Source code in src/SafeLens/core/registry.py
60 61 62 | |
register_probe(name, replace=False)
Register a probe class by name.
Source code in src/SafeLens/core/registry.py
55 56 57 | |