Giter Site home page Giter Site logo

Comments (2)

davisyoshida avatar davisyoshida commented on August 20, 2024 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.

giganttheo avatar giganttheo commented on August 20, 2024

ok, thank you for the ideas, pickle is indeed quite easier to use than msgpack here

from lorax.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.