Skip to content

[JAX] Adapt to Flax 0.7.1 - #353

Merged
timmoon10 merged 8 commits into
NVIDIA:mainfrom
mingxu1067:mingh/adapt_to_flax_071
Aug 3, 2023
Merged

[JAX] Adapt to Flax 0.7.1#353
timmoon10 merged 8 commits into
NVIDIA:mainfrom
mingxu1067:mingh/adapt_to_flax_071

Conversation

@mingxu1067

@mingxu1067mingxu1067 commented Aug 2, 2023

Copy link
Copy Markdown
Collaborator
  • Cast Flax collections to FrozenDict as WAR to adapt Flax 0.7.1.
  • Followed migrate to the normal dict to apapt to Flax 0.7.1.
    The root cause is that FrozenDict is removed from Flax 0.7.1, instead module.init() returns python built-in dict which has different behavior of pop with FrozenDict. FrozenDict's pop reuturns two outputs, remaining FrozenDict and popped value, but python built-in dict only returns popped value then in-place delete it in orginal object.

Meanwhile, add fully remove FrozenDict into TODO and will schedule time to fix internally.

Refer to #352

@mingxu1067

Copy link
Copy Markdown
CollaboratorAuthor

@zlsh80826, @jeng1220, @nouiz for viz.

@mingxu1067

Copy link
Copy Markdown
CollaboratorAuthor

/te-ci

@zlsh80826

Copy link
Copy Markdown
Collaborator

Hi Ming,
There is a guide on how to migrate to the normal dict. I think this would be better, the changes are small.

 def generate_layer(layer_cls, init_rng, diff_inputs, no_diff_inputs):
layer = layer_cls()
variables = layer.init(init_rng, *diff_inputs, *no_diff_inputs)
- others, params = variables.pop('params')
+ others, params = flax.core.pop(variables, 'params')
del variables
return layer, params, others
@@ -126,7 +126,7 @@ class TestEncoderLayer:
def sync_params(ref, target, attrs):
fuse_qkv = attrs.get(_KEY_OF_FUSE_QKV_PARAMS, True)
- unfreeze_target = target.unfreeze()
+ unfreeze_target = flax.core.unfreeze(target)
if fuse_qkv:
unfreeze_target['attention']['qkv']['kernel'] = \
jnp.reshape(ref['attention']['qkv']['kernel'],

@mingxu1067
mingxu1067force-pushed the mingh/adapt_to_flax_071 branch from 1f8618f to 72475eaCompareAugust 2, 2023 09:15
@mingxu1067

Copy link
Copy Markdown
CollaboratorAuthor

Thanks Reese for pointing this out, apopt this changes.

@mingxu1067

Copy link
Copy Markdown
CollaboratorAuthor

/te-ci

@nouiz

nouiz commented Aug 2, 2023

Copy link
Copy Markdown
Collaborator

Need to update the min flax version somewhere.

@mingxu1067
mingxu1067force-pushed the mingh/adapt_to_flax_071 branch from 663991b to 94b91cdCompareAugust 3, 2023 02:38
@mingxu1067

Copy link
Copy Markdown
CollaboratorAuthor

Need to update the min flax version somewhere.

Done, by adding it to requirements.txt in examples/jax.

@mingxu1067

Copy link
Copy Markdown
CollaboratorAuthor

/te-ci

mingxu1067and others added 6 commits August 3, 2023 09:10
Signed-off-by: Ming Huang <mingh@nvidia.com>
Signed-off-by: Ming Huang <mingh@nvidia.com>
Signed-off-by: Ming Huang <mingh@nvidia.com>
Refactor fp8 state
Signed-off-by: Tian Zheng (Engrg-Hardware 1) <tizheng@nvidia.com>
Signed-off-by: Ming Huang <mingh@nvidia.com>
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Signed-off-by: Ming Huang <mingh@nvidia.com>
Signed-off-by: Ming Huang <mingh@nvidia.com>
@mingxu1067
mingxu1067force-pushed the mingh/adapt_to_flax_071 branch from 982e5bd to 485fb2bCompareAugust 3, 2023 09:11
@mingxu1067

Copy link
Copy Markdown
CollaboratorAuthor

/te-ci

@nouiz

nouiz commented Aug 3, 2023

Copy link
Copy Markdown
Collaborator

Any idea why it is fixed? Should we drop this PR?

@timmoon10
timmoon10 self-requested a review August 3, 2023 16:23
@timmoon10

Copy link
Copy Markdown
Member

It looks like JAX-Toolbox is fetching this branch, so we should merge soon.

We should also update the Flax version in setup.py:

add_unique(install_reqs, ["jax", "flax"])

Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10
timmoon10 merged commit 403ade2 into NVIDIA:mainAug 3, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@mingxu1067@zlsh80826@nouiz@yhtang@timmoon10@Tom-Zheng@ksivaman