nnsight.patching
The patching module handles patching of classes and functions in modules.
-
class nnsight.patching.Patch(parent: Any, replacement: Any, key: str)[source]
Class representing a replacement of an attribute on a module.
-
obj
Object to replace.
- Type:
Any
-
replacement
Object that replaces.
- Type:
Any
-
parent
Module or class to replace attribute.
- Type:
Any
-
patch() → None[source]
Carries out the replacement of an object in a module/class.
-
restore() → None[source]
Carries out the restoration of the original object on the objects module/class.
-
class nnsight.patching.Patcher(patches: List[Patch] | None = None)[source]
Context manager that patches from a list of Patches on __enter__ and restores the patch on __exit__.
-
patches
- Type:
List[Patch]
-
add(patch: Patch) → None[source]
Adds a Patch to the patches. Also calls .patch() on the Patch.
- Parameters:
patch (Patch) – Patch to add.