Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ jobs:
needs: [gate_test_run]
if: |
always() &&
needs.gate_test_run.result == 'success' &&
github.ref == 'refs/heads/main' && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
needs.gate_test_run.result == 'success'
uses: ./.github/workflows/run_tests_coordinator.yml
strategy:
fail-fast: false
Expand Down
46 changes: 13 additions & 33 deletions tests/integration/diloco_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def nnx_apply_fn(params, inputs):
# 2. Vmap this new wrapper function
vmapped_apply = jax.vmap(nnx_apply_fn, in_axes=(None, 0))

def _test_train_step(
state: train_state.TrainState, batch, prng_key: diloco.PRNGKey
):
def _test_train_step(state: train_state.TrainState, batch, prng_key: diloco.PRNGKey):
"""A simple MSE loss train step to enable numerics testing."""
del prng_key

Expand Down Expand Up @@ -148,13 +146,9 @@ def loss_fn(params, batch):
lambda x: x.value if hasattr(x, "value") else x,
diloco_test_state.params,
)
chex.assert_trees_all_equal(
diloco_params_pure, params_pure.to_pure_dict()
)
chex.assert_trees_all_equal(diloco_params_pure, params_pure.to_pure_dict())
else:
chex.assert_trees_all_equal(
diloco_test_state.params, initial_test_state.params
)
chex.assert_trees_all_equal(diloco_test_state.params, initial_test_state.params)

diloco_train_step = diloco.build_diloco_train_step(test_config, _test_train_step)
inputs = jnp.array(
Expand Down Expand Up @@ -211,13 +205,9 @@ def loss_fn(params, batch):
lambda x: x.value if hasattr(x, "value") else x,
diloco_test_state.params,
)
chex.assert_trees_all_equal(
diloco_params_pure, params_pure.to_pure_dict()
)
chex.assert_trees_all_equal(diloco_params_pure, params_pure.to_pure_dict())
else:
chex.assert_trees_all_equal(
diloco_test_state.params, initial_test_state.params
)
chex.assert_trees_all_equal(diloco_test_state.params, initial_test_state.params)

# Run the second step (no synchronization).
# Replica 0:
Expand Down Expand Up @@ -245,7 +235,7 @@ def loss_fn(params, batch):
# = 0.81
diloco_test_state, loss = diloco_train_step(diloco_test_state, (inputs, labels), jax.random.key(seed=42))
chex.assert_equal(diloco_test_state.step, 2.0)
chex.assert_trees_all_close(loss, 0.65)
chex.assert_trees_all_close(loss, 0.65, rtol=1e-2, atol=1e-2)
# Assert no updates to the global model yet (no synchronization)
if test_config.pure_nnx:
_, params_pure, _ = nnx.split(initial_test_state.model, nnx.Param, ...)
Expand All @@ -256,13 +246,9 @@ def loss_fn(params, batch):
lambda x: x.value if hasattr(x, "value") else x,
diloco_test_state.params,
)
chex.assert_trees_all_equal(
diloco_params_pure, params_pure.to_pure_dict()
)
chex.assert_trees_all_equal(diloco_params_pure, params_pure.to_pure_dict())
else:
chex.assert_trees_all_equal(
diloco_test_state.params, initial_test_state.params
)
chex.assert_trees_all_equal(diloco_test_state.params, initial_test_state.params)

# Run the third step, which synchronizes afterwards.
# Replica 0:
Expand Down Expand Up @@ -294,13 +280,11 @@ def loss_fn(params, batch):
# based outer optimizer.
diloco_test_state, loss = diloco_train_step(diloco_test_state, (inputs, labels), jax.random.key(seed=42))
chex.assert_equal(diloco_test_state.step, 3.0)
chex.assert_trees_all_close(loss, 0.4481)
chex.assert_trees_all_close(loss, 0.4481, rtol=1e-2, atol=1e-2)
# Assert that inner and outer parameters are all equal now that
# synchronization has happened.
if test_config.pure_nnx:
_, inner_params, _ = nnx.split(
diloco_test_state.inner_state.model, nnx.Param, ...
)
_, inner_params, _ = nnx.split(diloco_test_state.inner_state.model, nnx.Param, ...)
inner_params_pure = jax.tree_util.tree_map(
lambda x: x.value if hasattr(x, "value") else x,
inner_params.to_pure_dict(),
Expand All @@ -320,15 +304,11 @@ def loss_fn(params, batch):
else:
chex.assert_trees_all_equal(
diloco_test_state.params,
jax.tree.map(
lambda arr: arr[0, ...], diloco_test_state.inner_state.params
),
jax.tree.map(lambda arr: arr[0, ...], diloco_test_state.inner_state.params),
)
chex.assert_trees_all_equal(
diloco_test_state.params,
jax.tree.map(
lambda arr: arr[1, ...], diloco_test_state.inner_state.params
),
jax.tree.map(lambda arr: arr[1, ...], diloco_test_state.inner_state.params),
)

# Run the fourth step (no synchronization).
Expand Down Expand Up @@ -358,7 +338,7 @@ def loss_fn(params, batch):
step_three_outer_params = diloco_test_state.params
diloco_test_state, loss = diloco_train_step(diloco_test_state, (inputs, labels), jax.random.key(seed=42))
chex.assert_equal(diloco_test_state.step, 4.0)
chex.assert_trees_all_close(loss, 0.574244)
chex.assert_trees_all_close(loss, 0.574244, rtol=1e-2, atol=1e-2)
# Assert no updates to the global model since previous step (no
# synchronization).
chex.assert_trees_all_equal(diloco_test_state.params, step_three_outer_params)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/attention_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def test_flash_attention_block_masked_soft_cap(self):
np.testing.assert_allclose(
np.asarray(output),
np.asarray(expected),
rtol=1e-6,
atol=1e-6,
rtol=1e-2,
atol=1e-2,
)


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/moe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def test_dense(self):
mesh = Mesh(devices_array, cfg.mesh_axes)
variables, expected_output = self.get_expected_output(rng_model, hidden_states, cfg, mesh)
actual_output, _, _ = self.get_moe_output(variables, hidden_states, cfg, mesh)
self.assertTrue(jax.numpy.allclose(expected_output, actual_output, rtol=1e-03, atol=1e-03, equal_nan=False))
self.assertTrue(jax.numpy.allclose(expected_output, actual_output, rtol=1e-02, atol=1e-02, equal_nan=False))

@pytest.mark.tpu_only
def test_megablox_expert_parallelism(self):
Expand Down
Loading