Comments (7)
Hi,
Unfortunately the library currently has no native support for saving and loading Laplace instances. However, you should be able to simply use pickle
to store and load the whole class instance, i.e. by using something like
import pickle
def save_laplace(la, filepath):
with open(filepath, 'wb') as output:
pickle.dump(la, output)
def load_laplace(filepath):
with open(filepath, 'rb') as input:
la = pickle.load(input)
return la
where la
is your instance of last-layer Laplace after fitting and filepath
is the path to the file in which you want to store the object. Just let me know if you run into issues with this approach.
We are planning to make this process more convenient in a future release, I have just opened an issue for this (#45).
from laplace.
Thank you for this workaround.
from laplace.
Hi @runame , I am getting this error when I am using your suggestion.
AttributeError: Can't pickle local object 'FeatureExtractor._get_hook..hook'
from laplace.
Ah I didn't test this approach with last-layer Laplace which uses the FeatureExtractor
with nested functions and pickle
can't handle this. Can you try using dill
instead of pickle
? Simply install it via pip install dill
.
import dill
def save_laplace(la, filepath):
with open(filepath, 'wb') as outpt:
dill.dump(la, outpt)
def load_laplace(filepath):
with open(filepath, 'rb') as inpt:
la = dill.load(inpt)
return la
from laplace.
@roysubhankar Did it work?
from laplace.
I had the same issue. It seems that the dill solved thanks!
from laplace.
Perfect, thanks for letting me know!
from laplace.
Related Issues (20)
- Implement heteroscedastic Laplace
- test_full_hess_curvlinops_vs_asdl of "regression" loss failed in Python 3.11 HOT 2
- Laplace Transform and Inverse laplace Transform for 2D images HOT 2
- Remove default `loss` for `optimize_prior_precision`
- Make try-except statement in `_gridsearch` more specific HOT 1
- Serialization: `torch.load(..., map_location="cpu")` doesn't map all tensors in `Laplace` instance HOT 2
- Make `torchmetrics` metrics the default in cross validation
- Efficient LLLA predictive samples
- Support for `torchtune`'s models and datasets
- Conform to PyTorch convention in the loss HOT 1
- Cache features in LLLA with MC predictive HOT 1
- Generalized dict-input mechanism
- Add example & doc for reward modeling functionality
- Handle feature reduction properly in LLLA
- Adding prior precision in `KronLaplace` is broken
- Support for structured Kronecker factors HOT 1
- Fast `KronLLLaplace` joint predictive
- Handle logits with more than 2 axes in `torch.func` diag and full backends
- Fix all linting issues and format all files with `ruff`
- Prior precision and prior mean of `LLLaplace` are hardcoded HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laplace.