# Path: init2winit/model_lib/base_model.py
# def _evaluate_batch(flax_module, params, batch_stats, batch, metrics_bundle,
#                     apply_one_hot_in_loss):
# def _predict_batch(flax_module,
#                    params,
#                    batch_stats,
#                    batch,
#                    output_activation_fn=None):
#   def __init__(self, hps, dataset_meta_data, loss_name, metrics_name):
#   def evaluate_batch(self, params, batch_stats, batch):
#   def predict_batch(self,
#                     params,
#                     batch_stats,
#                     batch,
#                     apply_output_activation_fn=False):
#   def training_cost(self, params, batch, batch_stats=None, dropout_rng=None):
#   def get_fake_batch(self, hps):
#   def build_flax_module(self):
# class BaseModel(object):
# 
# Path: init2winit/model_lib/model_utils.py
# ACTIVATIONS = {
#     'relu': jax.nn.relu,
#     'id': lambda x: x,
#     'tanh': jnp.tanh,
#     'sigmoid': jax.nn.sigmoid,
#     'silu': jax.nn.silu,
#     'leaky_relu': jax.nn.leaky_relu,
# }
# INITIALIZERS = {
#     'delta_orthogonal': initializers.delta_orthogonal,
#     'orthogonal': initializers.orthogonal,
#     'lecun_normal': lecun_normal,
#     'xavier_uniform': initializers.xavier_uniform,
# }
# class ScalarMultiply(nn.Module):
#   def __call__(self, x):
# def get_normalizer(normalizer,
#                    train,
#                    batch_size=None,
#                    virtual_batch_size=None,
#                    total_batch_size=None,
#                    dtype=jnp.float32,
#                    data_format='NHWC'):
#     def identity_wrapper(*args, **kwargs):
#       def identity(x, *args, **kwargs):
# def apply_label_smoothing(one_hot_targets, label_smoothing):
# def sync_batchnorm_stats(state):
# def cross_device_avg(pytree):
# def l2_regularization(params, l2_decay_rank_threshold):
# def flatten_dict(nested_dict, sep='/'):
# def rescale_layers(params, layer_rescale_factors):


from flax import linen as nn
from init2winit.model_lib import base_model
from init2winit.model_lib import model_utils
from jax.nn import initializers
from ml_collections.config_dict import config_dict
from scipy.stats import ortho_group
import jax.numpy as jnp
import numpy as np
    },
    batch_size=128,
    rng_seed=-1,
    # Note the dimension is set by input_shape.
    hessian_decay_power=1,
    noise_decay_power=1,
    nqm_mode='diagH_diagC',
    model_dtype='float32',
    l2_decay_factor=None,
))


class NQMLoss(nn.Module):
  """Loss for the NQM model.

  We assume the input is isotropic Gaussian noise, this is used to sample
  noise with covariance matrix C = N^T N with eigenspectrum defined by the
  params. To sample Gaussian noise with covariance C, we first sample
  z ~ N(0, I), then define eps = Nz, where N^T N = C. N is passed to apply as
  the noise_scaling matrix.

  Attrs:
    hessian: dxd psd matrix representing the loss hessian.
    noise_scaling: dxd matrix used to scale noise_input. This is a matrix N
      s.t. N^T N = C, where C will be the covariance of the scaled noise.
    train: Ignored, we add this to conform to the i2w model API. noise_input =
      jnp.asarray(noise_input) x = self.param('x', (noise_input.shape[-1],),
      initializers.ones)
  """
  hessian: model_utils.Array

# Path: init2winit/model_lib/base_model.py
# def _evaluate_batch(flax_module, params, batch_stats, batch, metrics_bundle,
#                     apply_one_hot_in_loss):
# def _predict_batch(flax_module,
#                    params,
#                    batch_stats,
#                    batch,
#                    output_activation_fn=None):
#   def __init__(self, hps, dataset_meta_data, loss_name, metrics_name):
#   def evaluate_batch(self, params, batch_stats, batch):
#   def predict_batch(self,
#                     params,
#                     batch_stats,
#                     batch,
#                     apply_output_activation_fn=False):
#   def training_cost(self, params, batch, batch_stats=None, dropout_rng=None):
#   def get_fake_batch(self, hps):
#   def build_flax_module(self):
# class BaseModel(object):
# 
# Path: init2winit/model_lib/model_utils.py
# ACTIVATIONS = {
#     'relu': jax.nn.relu,
#     'id': lambda x: x,
#     'tanh': jnp.tanh,
#     'sigmoid': jax.nn.sigmoid,
#     'silu': jax.nn.silu,
#     'leaky_relu': jax.nn.leaky_relu,
# }
# INITIALIZERS = {
#     'delta_orthogonal': initializers.delta_orthogonal,
#     'orthogonal': initializers.orthogonal,
#     'lecun_normal': lecun_normal,
#     'xavier_uniform': initializers.xavier_uniform,
# }
# class ScalarMultiply(nn.Module):
#   def __call__(self, x):
# def get_normalizer(normalizer,
#                    train,
#                    batch_size=None,
#                    virtual_batch_size=None,
#                    total_batch_size=None,
#                    dtype=jnp.float32,
#                    data_format='NHWC'):
#     def identity_wrapper(*args, **kwargs):
#       def identity(x, *args, **kwargs):
# def apply_label_smoothing(one_hot_targets, label_smoothing):
# def sync_batchnorm_stats(state):
# def cross_device_avg(pytree):
# def l2_regularization(params, l2_decay_rank_threshold):
# def flatten_dict(nested_dict, sep='/'):
# def rescale_layers(params, layer_rescale_factors):


# Path: init2winit/model_lib/nqm.py
from flax import linen as nn
from init2winit.model_lib import base_model
from init2winit.model_lib import model_utils
from jax.nn import initializers
from ml_collections.config_dict import config_dict
from scipy.stats import ortho_group
import jax.numpy as jnp
import numpy as np

    },
    batch_size=128,
    rng_seed=-1,
    # Note the dimension is set by input_shape.
    hessian_decay_power=1,
    noise_decay_power=1,
    nqm_mode='diagH_diagC',
    model_dtype='float32',
    l2_decay_factor=None,
))


class NQMLoss(nn.Module):
  """Loss for the NQM model.

  We assume the input is isotropic Gaussian noise, this is used to sample
  noise with covariance matrix C = N^T N with eigenspectrum defined by the
  params. To sample Gaussian noise with covariance C, we first sample
  z ~ N(0, I), then define eps = Nz, where N^T N = C. N is passed to apply as
  the noise_scaling matrix.

  Attrs:
    hessian: dxd psd matrix representing the loss hessian.
    noise_scaling: dxd matrix used to scale noise_input. This is a matrix N
      s.t. N^T N = C, where C will be the covariance of the scaled noise.
    train: Ignored, we add this to conform to the i2w model API. noise_input =
      jnp.asarray(noise_input) x = self.param('x', (noise_input.shape[-1],),
      initializers.ones)
  """
  hessian: model_utils.Array

  noise_scaling: model_utils.Array