-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
166 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <exceptions.h> | ||
#include <python_frontend/distributed_tensor.h> | ||
#include <utils.h> | ||
|
||
namespace nvfuser::python_frontend { | ||
|
||
void DistributedTensor::setAxisIsShardedOn( | ||
const int64_t axis, | ||
const ParallelType parallel_type) { | ||
const auto i = axis_sharded_on_.find(parallel_type); | ||
NVF_CHECK( | ||
i == axis_sharded_on_.end(), | ||
"Parallel type ", | ||
parallel_type, | ||
" was already used to shard axis ", | ||
i->second); | ||
axis_sharded_on_[parallel_type] = axis; | ||
} | ||
|
||
int64_t DistributedTensor::axisShardedOn( | ||
const ParallelType parallel_type) const { | ||
return getOrDefault(axis_sharded_on_, parallel_type, -1L); | ||
} | ||
|
||
} // namespace nvfuser::python_frontend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// clang-format off | ||
/* | ||
* SPDX-FileCopyrightText: Copyright (c) 2025-present NVIDIA CORPORATION & AFFILIATES. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
// clang-format on | ||
#pragma once | ||
|
||
#include <ATen/core/TensorBody.h> | ||
|
||
#include <multidevice/device_mesh.h> | ||
#include <type.h> | ||
|
||
namespace nvfuser::python_frontend { | ||
|
||
class DistributedTensor { | ||
public: | ||
explicit DistributedTensor( | ||
at::Tensor local_tensor, | ||
const DeviceMesh& mesh = DeviceMesh()) | ||
: local_(local_tensor), mesh_(mesh) {} | ||
DistributedTensor(const DistributedTensor&) = delete; | ||
DistributedTensor& operator=(const DistributedTensor&) = delete; | ||
DistributedTensor(DistributedTensor&&) = default; | ||
DistributedTensor& operator=(DistributedTensor&&) = default; | ||
|
||
const DeviceMesh& mesh() const { | ||
return mesh_; | ||
} | ||
|
||
at::Tensor local() const { | ||
return local_; | ||
} | ||
|
||
void setAxisIsShardedOn(int64_t axis, ParallelType parallel_type); | ||
|
||
int64_t axisShardedOn(ParallelType parallel_type) const; | ||
|
||
private: | ||
at::Tensor local_; | ||
DeviceMesh mesh_; | ||
std::unordered_map<ParallelType, int64_t> axis_sharded_on_; | ||
}; | ||
|
||
} // namespace nvfuser::python_frontend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters