google / google/flax

Swapping selected layers with a different layer.

Open
#3,585 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
7.3k
Forks
833
Avg merge
5h 11m
Merged PRs (30d)
5

Description

Hello!

I am pretty new to Jax/Flax. I was trying to implement to LoRA, although I could modify the state dict, would it be possible to modify the layers to accommodate the additional matrices on run time? Or, is there any other alternate approach to this, so that I could freeze the original weights and just keep the $A$ and $B$ matrices trainable?

I am able to modify the state dict by doing something like this:
```python
import jax
import jax.numpy as jnp

PRNGKey = jnp.ndarray

def get_param(path, param, rank: int, rng: PRNGKey):
if len(param.shape) == 1:
return param

a_dim, b_dim = param.shape
return {
"a": jax.random.normal(rng, shape=(a_dim, rank)),
"b": jnp.zeros(shape=(rank, b_dim)),
"w": param
}

new_params = jax.tree_util.tree_map_with_path(get_param, params, is_leaf=None)
```

Is there any maneuver I could do? Or, would I have to make drastic moves like re-defining the architecture?

Any suggestions would help!

Thank you!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.