# Path: flaxformer/sharding.py
# class AxisNames(tuple):
# def axis_names(*names: str) -> partitioning.AxisMetadata:
# def reduce_fn(x, y):
# def _get_single_sowed_value(value) -> AxisNames:
# def get_axis_names(variables):
# def check_params_and_axis_names_match(variables):
#   def _flatten_with_joined_names(xs):


from absl.testing import absltest
from flax import linen as nn
from flax.linen import partitioning
from jax import numpy as jnp
from flaxformer import sharding
import jax
# Copyright 2022 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for sharding."""




class BasicModule(nn.Module):

  def setup(self):
    self.x = self.param("x", nn.initializers.ones, (1, 2))
    self.sow(
        "params_axes",
        "x_axes",

# Path: flaxformer/sharding.py
# class AxisNames(tuple):
# def axis_names(*names: str) -> partitioning.AxisMetadata:
# def reduce_fn(x, y):
# def _get_single_sowed_value(value) -> AxisNames:
# def get_axis_names(variables):
# def check_params_and_axis_names_match(variables):
#   def _flatten_with_joined_names(xs):


# Path: flaxformer/sharding_test.py
from absl.testing import absltest
from flax import linen as nn
from flax.linen import partitioning
from jax import numpy as jnp
from flaxformer import sharding
import jax

# Copyright 2022 Google LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for sharding."""




class BasicModule(nn.Module):

  def setup(self):
    self.x = self.param("x", nn.initializers.ones, (1, 2))
    self.sow(
        "params_axes",
        "x_axes",

        sharding.axis_names("heads", "unmodeled"),