lit-wsl
My personal library of reusable Pytorch Lightning components
Features
Installation
With pip:
python -m pip install lit-wsl
With uv:
uv add lit-wsl
How to use it
IntermediateLayerGetter
Capture intermediate layer outputs during forward pass:
import torch
from torchvision.models import resnet18
from lit_wsl.models.intermediate_layer_getter import IntermediateLayerGetter
model = resnet18(pretrained=True)
# Specify which layers to capture: {layer_name: output_name}
return_layers = {"layer2": "feat1", "layer4": "feat2"}
layer_getter = IntermediateLayerGetter(model, return_layers, keep_output=True)
x = torch.randn(1, 3, 224, 224)
intermediate_outputs, final_output = layer_getter(x)
# intermediate_outputs is OrderedDict with keys "feat1" and "feat2"
print(intermediate_outputs["feat1"].shape) # torch.Size([1, 128, 28, 28])
WeightRenamer
Rename keys in checkpoint files:
from lit_wsl.models.weight_renamer import WeightRenamer
# Load checkpoint
renamer = WeightRenamer("old_model.pth")
# Remove common prefix
renamer.remove_prefix("model.")
# Rename specific keys
renamer.rename_keys({
"backbone.conv1": "encoder.conv1",
"head.fc": "classifier.fc"
})
# Save modified checkpoint
renamer.save("renamed_model.pth")
WeightMapper
Automatically map weights between different model architectures:
import torch
from lit_wsl.mapper.weight_mapper import WeightMapper
from lit_wsl.models.weight_renamer import WeightRenamer
# Define your models (with different layer names)
old_model = OldModelArchitecture()
new_model = NewModelArchitecture()
# Analyze and suggest mapping
mapper = WeightMapper(old_model, new_model)
mapping, unmatched = mapper.suggest_mapping(threshold=0.6)
# Apply mapping to checkpoint
renamer = WeightRenamer("old_weights.pth")
renamer.rename_keys(mapping)
renamer.save("adapted_weights.pth")
# Load adapted weights
new_model.load_state_dict(torch.load("adapted_weights.pth"))
Docs
uv run mkdocs build -f ./mkdocs.yml -d ./_build/
Update template
copier update --trust -A --vcs-ref=HEAD
Credits
Metadata
Release files for lit-wsl 0.3.4
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 |
|---|---|---|---|---|
| lit_wsl-0.3.4.tar.gz | 54.4 kB | Without provenance | Details for lit_wsl-0.3.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lit_wsl-0.3.4-py3-none-any.whl | Python 3 | none | any | Details for lit_wsl-0.3.4-py3-none-any.whl |
Total release size: 116.3 kB
Release files / lit_wsl-0.3.4.tar.gz
| Download URL | lit_wsl-0.3.4.tar.gz |
|---|---|
| Size | 54.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
303c00748b54d22ebbb1fee0d917d74bf7d506fe7b8382ad2ae326d95dee150e
|
|
BLAKE2b-256 checksum How to use checksums |
c238853327eaba1dfe6df493926d44562861b68b0b636147c7c00944b6e0f30a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","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":true}
|
Release files / lit_wsl-0.3.4-py3-none-any.whl
| Download URL | lit_wsl-0.3.4-py3-none-any.whl |
|---|---|
| Size | 61.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c85f4708619f1cf87becfac4d94f117f00de9b4f98be2994096ba954dcbe12d6
|
|
BLAKE2b-256 checksum How to use checksums |
f5791214dfd7d0cfc0df21e8067c97038f6ab436833ce26818a5ff43ec210398
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","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":true}
|
Security for lit-wsl 0.3.4
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.