Orivane
Orivane is a small Python library in alpha for making experimental changes to PyTorch models. It wraps methods with input, output, or replacement callbacks and registers patch modules with the model so they participate in device movement, training mode, checkpoints, and optimizers.
Installation
uv add orivane
Add a trainable adapter
Patch classes inherit from PatchBase and call super().__init__() so PyTorch can register modules assigned to the patch. By default, applying a patch freezes the model's existing parameters while leaving the patch's trainable parameters trainable.
import torch
import torch.nn as nn
from orivane import PatchBase, PatchType, inject, patch
model = nn.Linear(10, 5)
@patch(model=model)
class AdapterPatch(PatchBase):
def __init__(self):
super().__init__()
self.adapter = nn.Sequential(
nn.Linear(5, 16),
nn.GELU(),
nn.Linear(16, 5),
)
@inject(method="forward", at=PatchType.AFTER)
def add_adapter(self, output):
return output + self.adapter(output)
optimizer = torch.optim.AdamW(
(parameter for parameter in model.parameters() if parameter.requires_grad),
lr=1e-3,
)
x = torch.randn(32, 10)
target = torch.randn(32, 5)
loss = nn.MSELoss()(model(x), target)
optimizer.zero_grad()
loss.backward()
optimizer.step()
# Restore the original method and parameter trainability when finished.
AdapterPatch.unpatch()
The decorated class name refers to the applied patch instance. Its added modules are registered under the model, so they are included in model.parameters() and model.state_dict(), and follow model.to(...) and model.train() calls. Patch modules are moved to the device and dtype of the model's first parameter when the patch is applied.
Use train_only_added=False to leave the model's existing trainability settings unchanged:
@patch(model=model, train_only_added=False)
class FineTunePatch(PatchBase):
def __init__(self):
super().__init__()
Unpatching is safe to call more than once. It restores the wrapped method and the original requires_grad state of model parameters, and removes the patch module from the model.
Target a nested module
inject(method=...) accepts a method name on the model or a dotted path to a nested module method. For example, "layers.0.forward" targets the first module in a ModuleList named layers:
class BlockPatch(PatchBase):
def __init__(self):
super().__init__()
self.scale = nn.Parameter(torch.tensor(0.1))
@inject(method="layers.0.forward", at=PatchType.AFTER)
def scale_output(self, output):
return output * (1 + self.scale)
Apply it with @patch(model=model) as in the adapter example. BEFORE callbacks receive the method's positional and keyword arguments and may return (new_args, new_kwargs); AFTER callbacks receive and return the method result; OVERWRITE callbacks replace the method implementation.
Patch types
| Patch type | Behavior |
|---|---|
PatchType.BEFORE |
Optionally changes the arguments before the original method runs. |
PatchType.AFTER |
Changes the original method's result. |
PatchType.OVERWRITE |
Replaces the original method; only one overwrite is allowed per method. |
Patches operate on PyTorch modules and methods. They do not provide model-specific integrations, automatic layer discovery, distributed-training support, or quantization support.
Metadata
Release files for orivane 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| orivane-0.1.1.tar.gz | 4.6 kB | Without provenance | Details for orivane-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| orivane-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for orivane-0.1.1-py3-none-any.whl |
Total release size: 11.6 kB
Release files / orivane-0.1.1.tar.gz
| Download URL | orivane-0.1.1.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b78a3ba2359f5a1e308a7f1cb7f1eb7ccbc1ee2814be4bcdabfc96028194742
|
|
BLAKE2b-256 checksum How to use checksums |
f21d38da11d2f444d33468e95d3509697a91946a32f32bd1dbee0f3742beb698
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / orivane-0.1.1-py3-none-any.whl
| Download URL | orivane-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8663ecf36ffefac03a63a840fdb2b09d0cafe78b7169e541ac32772b54a7d569
|
|
BLAKE2b-256 checksum How to use checksums |
aa8d01636aad9c2bcacfd6b2e28dd1f2bc64514efadaea414a120052d9253e11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for orivane 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.