code: def _from_haiku_state(state: hk.State) -> MutableFlaxVariables:
      """Converts a Haiku state dict to a nested Flax collection."""
      variables = {}
      for name, module_state in state.items():
          collection_name, *mod_name, name = name.split("/")
          if collection_name not in variables:
              variables[collection_name] = {}
          if not mod_name and name == "~":
              variables[collection_name].update(module_state)
          else:
              nested_collection = variables[collection_name]
              for part in mod_name:
                  if part not in nested_collection:
                      nested_collection[part] = {}
                  nested_collection = nested_collection[part]
              nested_collection[name] = dict(module_state)
      return variables
  
file_path: dm-haiku/haiku/_src/flax/transform_flax.py
imports: from collections.abc import Mapping
  from typing import Any, Callable
  import flax.errors
  import flax.linen
  from haiku._src import base
  from haiku._src import filtering
  from haiku._src import lift
  from haiku._src import transform
  from haiku._src import typing
  from haiku._src.flax import utils
label_desc: Use image node_id 3 for calling a global function with example usage: _from_haiku_state(state) and returns: variables