Codesave
TL;DR
### When training
from codesave import checkpoint_to_wandb
wandb.init(...)
checkpoint_to_wandb(codebase_dirname)
### Time to recover
from codesave import Codebase, download_from_wandb
zipname = download_from_wandb(wandb_run_path)
with Codebase(zipname):
from src import model
model.whatever_you_want
Installation:
pip install git+https://github.com/dibyaghosh/codesave.git
Basic Usage
The easiest way to use codesave is using checkpoint or checkpoint_to_wandb, which will take all the files in the directory and create a zip file.
For example, suppose we have some repository with the following structure:
codebase/
src/
model.py
utils.py
train.py
eval.py
from codesave import checkpoint, checkpoint_to_wandb
checkpoint('codebase/', output_zipname='codebase.zip')
checkpoint_to_wandb('codebase/') # Stores it in the current wandb run (on the cloud)
This creates a zipfile that we can use anywhere else (even if we don't have codesave installed):
import sys
sys.path.append('codebase.zip')
import src.model # This will load the library directly from the zip file
Loading a Codebase
Using sys.path
The easiest way, doesn't require codesave to be installed
import sys
sys.path.append('codebase.zip') # Or PYTHONPATH=codebase.zip:$PYTHONPATH
import src.model # This will load the library directly from the zip file
Using Codebase
The second easiest way, but cannot be run multiple times in the same process (because old modules are not unloaded)
from codesave import Codebase
with Codebase('codebase.zip'):
from src import model
model.whatever_you_want
Using UniqueCodebase (general, recommended)
Using UniqueCodebase, we can load as many versions of a codebase as we want, and they can interact with each other.
The import notation is a little less clean, but it's necessary to avoid conflicts.
from codesave import UniqueCodebase
codebase1 = UniqueCodebase('codebase.zip')
codebase2 = UniqueCodebase('codebase_v2.zip')
model_v1 = codebase1.import_module('src.model') # equivalent to (from src import model as model_v1) from codebase.zip
model_v2 = codebase2.import_module('src.model') # equivalent to (from src import model as model_v2) from codebase_v2.zip
There are some syntactic sugar options (these do some magic juju to automatically assign the module to a variable)
codebase1.import_('src.model') # equivalent to `import src.model`
codebase1.import_('src.model', as_='model_v1') # equivalent to `import src.model as model_v1`
codebase1.from_import('src', ('model', 'utils')) # equivalent to `from src import model, utils`
codebase1.from_import('src', 'model', as_='model_v1') # equivalent to `from src import model as model_v1`
Just Unzip It
You can always unzip the zip file, and treat it as a normal directory.
Integration w/ wandb
When training,
from codesave import checkpoint_codebase_for_wandb
wandb.init(...)
checkpoint_codebase_for_wandb('codebase/')
Now at any point,
from codesave import load_codebase_from_wandb
load_codebase_from_wandb(wandb_run_name, output_zipname='codesave.zip')
# Now we can add to sys.path or ZipCodebase as before
Metadata
Release files for code-save 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| code_save-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for code_save-0.0.1-py3-none-any.whl |
Release files / code_save-0.0.1-py3-none-any.whl
| Download URL | code_save-0.0.1-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f99fa3afb55312787e4653245e2649dd0ba422dbdfb3edc34eef9a9a8545498a
|
|
BLAKE2b-256 checksum How to use checksums |
cf0c0b7a004aebd57a0397411508b837d8dea6b2b61b64bc315ccca81186e7e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.13
|
Security for code-save 0.0.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.