Comments (2)
The easiest thing to use is just pickle, the reason it won't work with FLAX's msgpack utilities out of the box is that you have to manually handle non-default types (see here).
If you specifically need to use msgpack, you can replace the LoraWeight instances with tuples by doing something like this:
TAG = '_LoraWeight'
def _lora_to_tuple(lora_weight):
return TAG, x.w, x.a, x.b, x.alpha
def _value_is_lora_tuple(x):
return isinstance(x, tuple) and x[0] == TAG
def _lora_tuple_to_original(tup):
_, w, a, b, alpha = tup
return LoraWeight(w=w, a=a, b=b, alpha=alpha)
def pytree_loras_to_tuple(pytree):
return jax.tree_map(
lambda x: _lora_to_tuple(x) if isinstance(x, LoraWeight) else x,
pytree,
is_leaf=lambda x: isinstance(x, LoraWeight)
)
def pytree_loras_to_tuple(pytree):
return jax.tree_map(
lambda x: _lora_to_tuple(x) if isinstance(x, LoraWeight) else x,
pytree,
is_leaf=lambda x: isinstance(x, LoraWeight)
)
def pytree_tuples_to_loras(pytree):
return jax.tree_map(
lambda x: _lora_tuple_to_original(x) if _value_is_lora_tuple(x) else x,
is_leaf=_value_is_lora_tuple
)
Another option would be to entirely flatten the pytree and serialize the resulting list, then unflatten it after deserialization.
from lorax.
ok, thank you for the ideas, pickle is indeed quite easier to use than msgpack here
from lorax.
Related Issues (11)
- Equinox support? HOT 3
- Integration into EasyLM HOT 4
- How to use lorax in python3.8 HOT 2
- lorax with haiku HOT 4
- LoRA for trasnformers are typically only applied to Linear layers, how to achieve this with this package? HOT 3
- Predicting LoRA weights HOT 34
- LoRA Hypernetworks for 3 dimensional kernels HOT 1
- ValueError: safe_zip() argument 2 is shorter than argument 1 HOT 7
- UserWarning in `qax` HOT 2
- Using lorax with class-based models HOT 1
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 lorax.