Skip to content

add JEPA example - #5660

Open
linjing-lab wants to merge 1 commit into
google:mainfrom
linjing-lab:linjing-lab
Open

linjing-lab wants to merge 1 commit into
google:mainfrom
linjing-lab:linjing-lab

Conversation

@linjing-lab

Copy link
Copy Markdown

What does this PR do?

Adds examples/jepa/, a temporal Joint-Embedding Predictive Architecture (JEPA) example built with Flax Linen. It trains an online encoder and predictor against an EMA (momentum) target encoder with a variance regularizer that prevents representation collapse, and reports a linear-probe R² comparison between the trained representation, a random-init representation and the raw last frame. The pedagogical point is how a Linen Module combines with raw JAX transformations: jax.flatten_util.ravel_pytree flattens the parameter PyTree into a vector so jit, value_and_grad, hessian and lax.while_loop can drive a hand-written damped BFGS solver with an analytic initial Hessian, Wolfe line search and BFGS rank-2 update, while Flax owns model definition and initialization (xavier_normal / zeros) and to_variables / to_params convert back to standard Flax variables / params PyTrees for use with TrainState + Optax. The example is split into base.py (MLP and _init_mlp), bfgs.py (make_bfgs), data.py (make_series), eval.py (linear_probe) and main.py (JEPA, gen_jepa, train_jepa and the __main__ demo).

Checklist

  • This PR fixes a minor issue (e.g.: typo or small bug) or improves the docs (you can dismiss the other checks if that's the case).
  • This change is discussed in a Github issue/discussion (please add a link).
  • The documentation and docstrings adhere to the documentation guidelines.
  • This change includes necessary high-coverage tests. (No quality testing = no merge!)

@linjing-lab linjing-lab left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check all files related to JEPA example.

@linjing-lab linjing-lab left a comment •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example runs normally in Python 3.12, JAX, and Flax environments.

This branch has not been deployed

No deployments
Sign up for free to 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.

1 participant