Skip to content

Commit

Permalink
[TT-Train] Add multidevice support to dropout (#16823)
Browse files Browse the repository at this point in the history
### Problem description
Previously same mask was generated for different devices with the same
seed.
### What's changed
Now per-device seed is seed+device_id. So we are generating different
mask for different devices.

### Checklist
- [x] Post commit CI passes
- [x] Blackhole Post commit (if applicable)
- [x] Model regression CI testing passes (if applicable)
- [x] Device performance regression CI testing passes (if applicable)
- [x] **(For models and ops writers)** Full [new
models](https://github.com/tenstorrent/tt-metal/actions/workflows/full-new-models-suite.yaml)
tests passes
- [x] New/Existing tests provide coverage for changes
  • Loading branch information
dmakoviichuk-tt authored Jan 16, 2025
1 parent d1ac518 commit 3b589f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions tt-train/tests/core/n300_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,25 @@ TEST_F(N300UtilsTest, TestXTensorShardAxis3Matmul) {
// (128, 64) X (64, 256) => (128, 256)
EXPECT_TRUE(xt::allclose(mul_res, xtensors_back[0], /*rtol=*/1e-3, /*atol=*/1e-2));
}

TEST_F(N300UtilsTest, DropoutDifferentSeed) {
uint32_t dropout_seed1 = 42;
float scale = 2.0F;
float prob = 0.5F;
xt::random::seed(42);
auto* device = &ttml::autograd::ctx().get_device();
auto mesh_shape = device->shape();
device->enable_program_cache();
auto shapes = {std::vector<int>{64, 1, 256, 384}, std::vector<int>{1, 1, 32, 32}};
for (auto& shape : shapes) {
fmt::println("Testing shape: {}", shape);
xt::xarray<float> xtensor = xt::ones<float>(shape);
ttml::core::XTensorToMeshVariant<float> replicate_composer =
ttml::core::ReplicateXTensorToMesh<float>(mesh_shape);
auto xtensor_tensor = ttml::core::from_xtensor(xtensor, device, replicate_composer);
auto out_tensor = ttnn::experimental::dropout(xtensor_tensor, prob, scale, dropout_seed1);
ttml::core::MeshToXTensorVariant<float> identity_composer = ttml::core::VectorMeshToXTensor<float>(mesh_shape);
auto xtensors_back = ttml::core::to_xtensor(out_tensor, identity_composer);
EXPECT_FALSE(xt::allclose(xtensors_back[0], xtensors_back[1], /*rtol=*/1e-4, /*atol=*/1e-3));
}
}
3 changes: 2 additions & 1 deletion ttnn/cpp/ttnn/operations/experimental/dropout/dropout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include "dropout.hpp"
namespace ttnn::operations::experimental {
Tensor DropoutOperation::invoke(const Tensor& input_tensor, float prob, float scale, uint32_t seed) {
return ttnn::prim::dropout(input_tensor, prob, scale, seed, DataType::BFLOAT16);
auto chip_id = static_cast<uint32_t>(input_tensor.device()->id());
return ttnn::prim::dropout(input_tensor, prob, scale, seed + chip_id, DataType::BFLOAT16);
}

} // namespace ttnn::operations::experimental

0 comments on commit 3b589f1

Please sign in to comment.