GithubHelp home page GithubHelp logo

Easily freeze parameters about dynax HOT 2 CLOSED

fhchl avatar fhchl commented on June 13, 2024
Easily freeze parameters

from dynax.

Comments (2)

fhchl avatar fhchl commented on June 13, 2024

An example:

import equinox as eqx
import jax.tree_util as jtu

# Class of which all parameters are trained
class Class1(eqx.Module): 
  param1: float
  param2: float

# inherits param1, but param2 is set as fixed now
class Class2(Class1): 
  param2: float = eqx.static_field() 

# make two examples
c1 = Class1(1, 2)
c2 = Class2(1, 3) 

# with tree flatten we can check which parameters are part of the pytree
# (they are trainable) and which are part of the structure (they are fixed)
print(jtu.tree_flatten(c1), jtu.tree_flatten(c2)) 

# this function returns a copy of obj, that behaves like cls
def change_class(obj, cls):
  # make a copy 
  flat, treedef = jtu.tree_flatten(obj)
  obj = treedef.unflatten(flat)
  # change class object.__setattr__(obj, "__class__", cls)
  return obj
  
# the value 2 is now part of the strucure. seems to work!
c1 = change_class(c1, Class2)
print(jtu.tree_flatten(c1))

from dynax.

fhchl avatar fhchl commented on June 13, 2024

Fixed by new free_field, static_field functionality.

from dynax.

Related Issues (20)

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.