Giter Site home page Giter Site logo

Merge FlatMappings with DeviceArray as values raises `AttributeError: 'DeviceArray' object has no attribute 'items'` about dm-haiku HOT 2 CLOSED

google-deepmind avatar google-deepmind commented on May 21, 2024
Merge FlatMappings with DeviceArray as values raises `AttributeError: 'DeviceArray' object has no attribute 'items'`

from dm-haiku.

Comments (2)

tomhennigan avatar tomhennigan commented on May 21, 2024

Hey @sebamenabar , the utilities in data_structures rely on being passed a "two level" mapping (in Haiku the params and state dicts have the following structure: {'module_name': {'parameter_name': parameter_value}}), when you do fast = params['fast'] you are getting one of the inner mappings which cannot be used with functions expecting a two level mapping.

There is an easy solution though 😄 I would suggest using partition and merge to split and combine the params dict while maintaining two level mappings:

params = f.init(..)

# Split fast and slow params to operate on them independently.
predicate = lambda m, n, v: m == 'fast_weights'
fast_params, slow_params = hk.data_structures.partition(predicate, params)

# Recombine fast and slow to (for example) pass to apply.
params = hk.data_structures.merge(fast_params, slow_params)
out = f.apply(params, ..)

Fabio added an example utility function (jax_fn_with_filter) to the tests [0] when he authored these, you may find that useful too.

[0] https://github.com/deepmind/dm-haiku/blob/master/haiku/_src/filtering_test.py

from dm-haiku.

sebamenabar avatar sebamenabar commented on May 21, 2024

Thanks tom!

from dm-haiku.

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.