未验证 提交 1f94081d 编写于 作者: L LiYuRio 提交者: GitHub

remove namespace for dist attr and process mesh (#56449)

上级 95c4bb41
...@@ -40,6 +40,10 @@ class VarDesc; ...@@ -40,6 +40,10 @@ class VarDesc;
} // namespace framework } // namespace framework
namespace distributed { namespace distributed {
using phi::distributed::ProcessMesh;
using phi::distributed::TensorDistAttr;
namespace auto_parallel { namespace auto_parallel {
using framework::BlockDesc; using framework::BlockDesc;
...@@ -48,8 +52,6 @@ using framework::ProgramDesc; ...@@ -48,8 +52,6 @@ using framework::ProgramDesc;
using framework::VarDesc; using framework::VarDesc;
using phi::distributed::auto_parallel::OperatorDistAttrProto; using phi::distributed::auto_parallel::OperatorDistAttrProto;
using phi::distributed::auto_parallel::ProcessMesh;
using phi::distributed::auto_parallel::TensorDistAttr;
constexpr const char* kDefault = "default"; constexpr const char* kDefault = "default";
......
...@@ -19,10 +19,10 @@ limitations under the License. */ ...@@ -19,10 +19,10 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace distributed { namespace distributed {
namespace auto_parallel { using phi::distributed::ProcessMesh;
using phi::distributed::TensorDistAttr;
using phi::distributed::auto_parallel::ProcessMesh; namespace auto_parallel {
using phi::distributed::auto_parallel::TensorDistAttr;
/** /**
* A unified data class for inferring distributed attributes * A unified data class for inferring distributed attributes
......
...@@ -99,8 +99,7 @@ void GradTensorHolder::CopyValueFromTensor(size_t slot_id, ...@@ -99,8 +99,7 @@ void GradTensorHolder::CopyValueFromTensor(size_t slot_id,
auto dist_tensor = std::make_shared<phi::distributed::DistTensor>( auto dist_tensor = std::make_shared<phi::distributed::DistTensor>(
dense_temp, dense_temp,
dense_temp->meta(), dense_temp->meta(),
std::make_shared< std::make_shared<phi::distributed::TensorDistAttr>());
phi::distributed::auto_parallel::TensorDistAttr>());
temp.set_impl(dist_tensor); temp.set_impl(dist_tensor);
buffer_[slot_id][rank] = temp; buffer_[slot_id][rank] = temp;
#endif #endif
......
...@@ -28,7 +28,7 @@ limitations under the License. */ ...@@ -28,7 +28,7 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace framework { namespace framework {
using phi::distributed::auto_parallel::TensorDistAttr; using phi::distributed::TensorDistAttr;
// convert between std::vector and protobuf repeated. // convert between std::vector and protobuf repeated.
template <typename T> template <typename T>
......
...@@ -40,21 +40,21 @@ namespace paddle { ...@@ -40,21 +40,21 @@ namespace paddle {
namespace pybind { namespace pybind {
using paddle::distributed::auto_parallel::DistTensorSpec; using paddle::distributed::auto_parallel::DistTensorSpec;
using paddle::distributed::auto_parallel::kDefault;
using paddle::distributed::auto_parallel::OperatorDistAttr; using paddle::distributed::auto_parallel::OperatorDistAttr;
using paddle::distributed::auto_parallel::SPMDRuleBase; using paddle::distributed::auto_parallel::SPMDRuleBase;
using paddle::distributed::auto_parallel::SPMDRuleMap; using paddle::distributed::auto_parallel::SPMDRuleMap;
using paddle::framework::OpDesc; using paddle::framework::OpDesc;
using paddle::framework::VarDesc; using paddle::framework::VarDesc;
using phi::distributed::ProcessMesh;
using phi::distributed::TensorDistAttr;
using phi::distributed::auto_parallel::Device; using phi::distributed::auto_parallel::Device;
using phi::distributed::auto_parallel::DeviceCapability; using phi::distributed::auto_parallel::DeviceCapability;
using phi::distributed::auto_parallel::DeviceMesh; using phi::distributed::auto_parallel::DeviceMesh;
using phi::distributed::auto_parallel::DistributedMapper; using phi::distributed::auto_parallel::DistributedMapper;
using phi::distributed::auto_parallel::kDefault;
using phi::distributed::auto_parallel::Link; using phi::distributed::auto_parallel::Link;
using phi::distributed::auto_parallel::LinkCapability; using phi::distributed::auto_parallel::LinkCapability;
using phi::distributed::auto_parallel::Machine; using phi::distributed::auto_parallel::Machine;
using phi::distributed::auto_parallel::ProcessMesh;
using phi::distributed::auto_parallel::TensorDistAttr;
PyTypeObject *g_tensor_dist_attr_pytype = nullptr; PyTypeObject *g_tensor_dist_attr_pytype = nullptr;
......
...@@ -46,7 +46,7 @@ limitations under the License. */ ...@@ -46,7 +46,7 @@ limitations under the License. */
#include "paddle/phi/core/distributed/auto_parallel/dist_attr.h" #include "paddle/phi/core/distributed/auto_parallel/dist_attr.h"
#include "paddle/phi/core/distributed/auto_parallel/dist_tensor.h" #include "paddle/phi/core/distributed/auto_parallel/dist_tensor.h"
using phi::distributed::DistTensor; using phi::distributed::DistTensor;
using phi::distributed::auto_parallel::TensorDistAttr; using phi::distributed::TensorDistAttr;
#endif #endif
namespace paddle { namespace paddle {
...@@ -737,7 +737,7 @@ Tensor is the basic data structure in PaddlePaddle. There are some ways to creat ...@@ -737,7 +737,7 @@ Tensor is the basic data structure in PaddlePaddle. There are some ways to creat
* ** zero_copy: bool, * ** zero_copy: bool,
* ** name: std::string, * ** name: std::string,
* ** stop_gradient: bool, * ** stop_gradient: bool,
* ** dist_attr: phi::distributed::auto_parallel::TensorDistAttr) * ** dist_attr: phi::distributed::TensorDistAttr)
* 4. * 4.
* def __init__ ( * def __init__ (
* ** value: ndarray) * ** value: ndarray)
...@@ -751,7 +751,7 @@ Tensor is the basic data structure in PaddlePaddle. There are some ways to creat ...@@ -751,7 +751,7 @@ Tensor is the basic data structure in PaddlePaddle. There are some ways to creat
* ** tensor: Tensor, * ** tensor: Tensor,
* ** place: paddle::platform::Place, * ** place: paddle::platform::Place,
* ** name: std::string, * ** name: std::string,
* ** dist_attr: phi::distributed::auto_parallel::TensorDistAttr) * ** dist_attr: phi::distributed::TensorDistAttr)
* 7. (multi-place) (should have at least one parameter, one parameter similar * 7. (multi-place) (should have at least one parameter, one parameter similar
* to case 5, zero parameter equals to case 1.) * to case 5, zero parameter equals to case 1.)
* def __init__ ( * def __init__ (
......
...@@ -546,7 +546,7 @@ platform::Place CastPyArg2Place(PyObject* obj, ssize_t arg_pos) { ...@@ -546,7 +546,7 @@ platform::Place CastPyArg2Place(PyObject* obj, ssize_t arg_pos) {
} }
#ifdef PADDLE_WITH_DISTRIBUTE #ifdef PADDLE_WITH_DISTRIBUTE
using phi::distributed::auto_parallel::TensorDistAttr; using phi::distributed::TensorDistAttr;
std::shared_ptr<TensorDistAttr> CastPyArg2DistAttr(PyObject* obj, std::shared_ptr<TensorDistAttr> CastPyArg2DistAttr(PyObject* obj,
ssize_t arg_pos) { ssize_t arg_pos) {
if (PyObject_IsInstance( if (PyObject_IsInstance(
...@@ -891,8 +891,7 @@ PyObject* ToPyObject(const phi::distributed::DistTensor* value) { ...@@ -891,8 +891,7 @@ PyObject* ToPyObject(const phi::distributed::DistTensor* value) {
return obj.ptr(); return obj.ptr();
} }
PyObject* ToPyObject( PyObject* ToPyObject(const phi::distributed::TensorDistAttr* value) {
const phi::distributed::auto_parallel::TensorDistAttr* value) {
auto obj = ::pybind11::cast(value, py::return_value_policy::reference); auto obj = ::pybind11::cast(value, py::return_value_policy::reference);
obj.inc_ref(); obj.inc_ref();
return obj.ptr(); return obj.ptr();
......
...@@ -121,8 +121,7 @@ PyObject* ToPyObject(const platform::Place& value); ...@@ -121,8 +121,7 @@ PyObject* ToPyObject(const platform::Place& value);
PyObject* ToPyObject(const phi::DenseTensor* value); PyObject* ToPyObject(const phi::DenseTensor* value);
#ifdef PADDLE_WITH_DISTRIBUTE #ifdef PADDLE_WITH_DISTRIBUTE
PyObject* ToPyObject(const phi::distributed::DistTensor* value); PyObject* ToPyObject(const phi::distributed::DistTensor* value);
PyObject* ToPyObject( PyObject* ToPyObject(const phi::distributed::TensorDistAttr* value);
const phi::distributed::auto_parallel::TensorDistAttr* value);
#endif #endif
PyObject* ToPyObject(const phi::SelectedRows* value); PyObject* ToPyObject(const phi::SelectedRows* value);
PyObject* ToPyObject(const paddle::framework::proto::VarType::Type& dtype); PyObject* ToPyObject(const paddle::framework::proto::VarType::Type& dtype);
...@@ -314,8 +313,8 @@ paddle::DataType CastPyArg2DataTypeDirectly(PyObject* obj, ...@@ -314,8 +313,8 @@ paddle::DataType CastPyArg2DataTypeDirectly(PyObject* obj,
ssize_t arg_pos); ssize_t arg_pos);
#ifdef PADDLE_WITH_DISTRIBUTE #ifdef PADDLE_WITH_DISTRIBUTE
std::shared_ptr<phi::distributed::auto_parallel::TensorDistAttr> std::shared_ptr<phi::distributed::TensorDistAttr> CastPyArg2DistAttr(
CastPyArg2DistAttr(PyObject* obj, ssize_t arg_pos); PyObject* obj, ssize_t arg_pos);
#endif #endif
paddle::optional<paddle::Tensor> GetOptionalTensorFromArgs( paddle::optional<paddle::Tensor> GetOptionalTensorFromArgs(
......
...@@ -44,8 +44,8 @@ PyTypeObject *g_blockdesc_pytype = nullptr; ...@@ -44,8 +44,8 @@ PyTypeObject *g_blockdesc_pytype = nullptr;
namespace pd = paddle::framework; namespace pd = paddle::framework;
namespace jit = paddle::jit; namespace jit = paddle::jit;
using paddle::distributed::TensorDistAttr;
using paddle::distributed::auto_parallel::OperatorDistAttr; using paddle::distributed::auto_parallel::OperatorDistAttr;
using paddle::distributed::auto_parallel::TensorDistAttr;
template <typename T> template <typename T>
static pybind11::bytes SerializeMessage( static pybind11::bytes SerializeMessage(
......
...@@ -541,8 +541,7 @@ phi::distributed::DistTensor* SetKernelDistOutput(Tensor* out) { ...@@ -541,8 +541,7 @@ phi::distributed::DistTensor* SetKernelDistOutput(Tensor* out) {
if (out->impl() == nullptr) { if (out->impl() == nullptr) {
auto dense_t = std::make_shared<phi::DenseTensor>(); auto dense_t = std::make_shared<phi::DenseTensor>();
// TODO(chenweihang): polish code, dist_attr is null now // TODO(chenweihang): polish code, dist_attr is null now
auto dist_attr = auto dist_attr = std::make_shared<phi::distributed::TensorDistAttr>();
std::make_shared<phi::distributed::auto_parallel::TensorDistAttr>();
auto dist_t = std::make_shared<phi::distributed::DistTensor>( auto dist_t = std::make_shared<phi::distributed::DistTensor>(
dense_t, phi::DenseTensorMeta(), dist_attr); dense_t, phi::DenseTensorMeta(), dist_attr);
out->set_impl(dist_t); out->set_impl(dist_t);
......
...@@ -22,7 +22,8 @@ limitations under the License. */ ...@@ -22,7 +22,8 @@ limitations under the License. */
namespace phi { namespace phi {
namespace distributed { namespace distributed {
namespace auto_parallel { using phi::distributed::auto_parallel::str_join;
using phi::distributed::auto_parallel::TensorDistAttrProto;
// partial is not allow annotated by user by now. // partial is not allow annotated by user by now.
std::vector<std::string> TensorDistAttr::fields_{ std::vector<std::string> TensorDistAttr::fields_{
...@@ -343,6 +344,5 @@ std::string TensorDistAttr::partial_status_string() const { ...@@ -343,6 +344,5 @@ std::string TensorDistAttr::partial_status_string() const {
return partial_status_str; return partial_status_str;
} }
} // namespace auto_parallel
} // namespace distributed } // namespace distributed
} // namespace phi } // namespace phi
...@@ -30,9 +30,6 @@ limitations under the License. */ ...@@ -30,9 +30,6 @@ limitations under the License. */
namespace phi { namespace phi {
namespace distributed { namespace distributed {
namespace auto_parallel {
constexpr const char* kDefault = "default";
class TensorDistAttr { class TensorDistAttr {
public: public:
...@@ -125,9 +122,9 @@ class TensorDistAttr { ...@@ -125,9 +122,9 @@ class TensorDistAttr {
// in partial-support-stage-I partial will always be a runtime attribute, // in partial-support-stage-I partial will always be a runtime attribute,
// there is not need to serialize it. support the partial serialization in // there is not need to serialize it. support the partial serialization in
// future partial-support-stage-II. // future partial-support-stage-II.
void from_proto(const TensorDistAttrProto& proto); void from_proto(const auto_parallel::TensorDistAttrProto& proto);
TensorDistAttrProto to_proto() const; auto_parallel::TensorDistAttrProto to_proto() const;
std::string serialize_to_string(); std::string serialize_to_string();
...@@ -157,6 +154,5 @@ inline bool operator!=(const TensorDistAttr& lhs, const TensorDistAttr& rhs) { ...@@ -157,6 +154,5 @@ inline bool operator!=(const TensorDistAttr& lhs, const TensorDistAttr& rhs) {
return !operator==(lhs, rhs); return !operator==(lhs, rhs);
} }
} // namespace auto_parallel
} // namespace distributed } // namespace distributed
} // namespace phi } // namespace phi
...@@ -22,11 +22,7 @@ namespace phi { ...@@ -22,11 +22,7 @@ namespace phi {
class DenseTensorUtils; class DenseTensorUtils;
namespace distributed { namespace distributed {
namespace auto_parallel {
class TensorDistAttr; class TensorDistAttr;
}
using auto_parallel::TensorDistAttr;
class DistTensor final class DistTensor final
: public phi::TensorBase, : public phi::TensorBase,
......
...@@ -12,15 +12,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ...@@ -12,15 +12,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. */ limitations under the License. */
#include "paddle/phi/core/distributed/auto_parallel/process_mesh.h"
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include "paddle/phi/core/distributed/auto_parallel/process_mesh.h"
#include "paddle/phi/core/distributed/auto_parallel/utils.h" #include "paddle/phi/core/distributed/auto_parallel/utils.h"
namespace phi { namespace phi {
namespace distributed { namespace distributed {
namespace auto_parallel {
using phi::distributed::auto_parallel::has_duplicates;
using phi::distributed::auto_parallel::ProcessMeshProto;
using phi::distributed::auto_parallel::str_join;
ProcessMesh::ProcessMesh(const std::vector<int64_t> &shape, ProcessMesh::ProcessMesh(const std::vector<int64_t> &shape,
const std::vector<int64_t> &process_ids, const std::vector<int64_t> &process_ids,
...@@ -129,6 +133,5 @@ bool operator==(const ProcessMesh &lhs, const ProcessMesh &rhs) { ...@@ -129,6 +133,5 @@ bool operator==(const ProcessMesh &lhs, const ProcessMesh &rhs) {
return true; return true;
} }
} // namespace auto_parallel
} // namespace distributed } // namespace distributed
} // namespace phi } // namespace phi
...@@ -27,7 +27,6 @@ limitations under the License. */ ...@@ -27,7 +27,6 @@ limitations under the License. */
namespace phi { namespace phi {
namespace distributed { namespace distributed {
namespace auto_parallel {
class ProcessMesh { class ProcessMesh {
public: public:
...@@ -48,7 +47,7 @@ class ProcessMesh { ...@@ -48,7 +47,7 @@ class ProcessMesh {
int64_t ndim() const { return shape_.size(); } int64_t ndim() const { return shape_.size(); }
int64_t dim_size(int64_t dim) const { int64_t dim_size(int64_t dim) const {
int64_t cdim = canonical_dim(dim, shape_.size()); int64_t cdim = auto_parallel::canonical_dim(dim, shape_.size());
return shape_[cdim]; return shape_[cdim];
} }
...@@ -68,8 +67,8 @@ class ProcessMesh { ...@@ -68,8 +67,8 @@ class ProcessMesh {
// ProcessMesh from_string(const std::string& mesh_str); // ProcessMesh from_string(const std::string& mesh_str);
std::string to_string() const; std::string to_string() const;
static ProcessMesh from_proto(const ProcessMeshProto& proto); static ProcessMesh from_proto(const auto_parallel::ProcessMeshProto& proto);
ProcessMeshProto to_proto() const; auto_parallel::ProcessMeshProto to_proto() const;
private: private:
std::vector<int64_t> shape_; std::vector<int64_t> shape_;
...@@ -88,6 +87,5 @@ inline bool operator!=(const ProcessMesh& lhs, const ProcessMesh& rhs) { ...@@ -88,6 +87,5 @@ inline bool operator!=(const ProcessMesh& lhs, const ProcessMesh& rhs) {
return !operator==(lhs, rhs); return !operator==(lhs, rhs);
} }
} // namespace auto_parallel
} // namespace distributed } // namespace distributed
} // namespace phi } // namespace phi
...@@ -19,12 +19,9 @@ namespace phi { ...@@ -19,12 +19,9 @@ namespace phi {
class DeviceContext; class DeviceContext;
namespace distributed { namespace distributed {
namespace auto_parallel {
class TensorDistAttr;
} // namespace auto_parallel
class DistTensor; class DistTensor;
using auto_parallel::TensorDistAttr; class TensorDistAttr;
class ReshardFunction { class ReshardFunction {
public: public:
......
...@@ -27,13 +27,7 @@ class DeviceContext; ...@@ -27,13 +27,7 @@ class DeviceContext;
namespace distributed { namespace distributed {
class CommContext; class CommContext;
namespace auto_parallel {
class ProcessMesh; class ProcessMesh;
} // namespace auto_parallel
using auto_parallel::ProcessMesh;
bool IsDimsMappingShard(const std::vector<int64_t>& dims_mapping); bool IsDimsMappingShard(const std::vector<int64_t>& dims_mapping);
......
...@@ -17,11 +17,11 @@ limitations under the License. */ ...@@ -17,11 +17,11 @@ limitations under the License. */
#include "glog/logging.h" #include "glog/logging.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "paddle/fluid/distributed/auto_parallel/dist_attr.h"
#include "paddle/fluid/framework/block_desc.h" #include "paddle/fluid/framework/block_desc.h"
#include "paddle/fluid/framework/op_desc.h" #include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/framework/var_desc.h" #include "paddle/fluid/framework/var_desc.h"
#include "paddle/phi/core/distributed/auto_parallel/dist_attr.h"
namespace phi { namespace phi {
namespace distributed { namespace distributed {
...@@ -127,7 +127,8 @@ TEST(DistAttr, ctor) { ...@@ -127,7 +127,8 @@ TEST(DistAttr, ctor) {
EXPECT_EQ(out_dist_attr.verify(get_tensor_shape(out)), true); EXPECT_EQ(out_dist_attr.verify(get_tensor_shape(out)), true);
OperatorDistAttr mul_dist_attr(*op); OperatorDistAttr mul_dist_attr(*op);
EXPECT_EQ(mul_dist_attr.impl_type(), kDefault); EXPECT_EQ(mul_dist_attr.impl_type(),
paddle::distributed::auto_parallel::kDefault);
EXPECT_EQ(mul_dist_attr.impl_idx(), 0); EXPECT_EQ(mul_dist_attr.impl_idx(), 0);
EXPECT_EQ(mul_dist_attr.is_recompute(), false); EXPECT_EQ(mul_dist_attr.is_recompute(), false);
EXPECT_EQ(mul_dist_attr.is_annotated("process_mesh"), false); EXPECT_EQ(mul_dist_attr.is_annotated("process_mesh"), false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册