Skip to content

Commit 2d6a9d7

Browse files
committed
Fix
1 parent 03dca7f commit 2d6a9d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3492
-1313
lines changed

paddle/fluid/framework/CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ foreach(OP_DEF_FILE ${OP_DEF_FILES})
101101
endforeach()
102102
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/op_def.pbtxt "{\"\",\"\"}};\n}")
103103

104-
cc_library(
105-
string_array
106-
SRCS string_array.cc
107-
DEPS utf8proc phi common)
108-
109104
cc_library(
110105
data_type
111106
SRCS data_type.cc

paddle/fluid/framework/operator.cc

+3
Original file line numberDiff line numberDiff line change
@@ -3257,6 +3257,9 @@ void OperatorWithKernel::BuildPhiKernelContext(
32573257
} else if (var->IsType<framework::Vocab>()) {
32583258
tensor_in = &(var->Get<framework::Vocab>());
32593259
phi_kernel_context->EmplaceBackInputWithoutSetRange(tensor_in);
3260+
} else if (var->IsType<framework::Strings>()) {
3261+
tensor_in = &(var->Get<framework::Strings>());
3262+
phi_kernel_context->EmplaceBackInputWithoutSetRange(tensor_in);
32603263
} else if (var->IsType<framework::FeedList>()) {
32613264
tensor_in = &(var->Get<framework::FeedList>());
32623265
phi_kernel_context->EmplaceBackInputWithoutSetRange(tensor_in);

paddle/fluid/framework/raw_tensor.h

+1-86
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,4 @@ See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

1515
#pragma once
16-
17-
#include <unordered_map>
18-
19-
#include "paddle/phi/core/enforce.h"
20-
#include "paddle/phi/core/extended_tensor.h"
21-
#include "paddle/utils/any.h"
22-
23-
namespace paddle {
24-
namespace framework {
25-
26-
/// \brief Fluid Kernel and PHI Kernel will be unified in the future.
27-
/// So, we need a class in PHI that can represent the RawTensor type in Fluid.
28-
/// The RawTensor is for PHI Kernel that has RawTensor type arguments.
29-
class RawTensor : public phi::ExtendedTensor,
30-
public phi::TypeInfoTraits<phi::TensorBase, RawTensor> {
31-
public:
32-
RawTensor() = default;
33-
34-
RawTensor(RawTensor&& other) = default;
35-
36-
RawTensor(const RawTensor& other) = default;
37-
38-
RawTensor& operator=(RawTensor&& other) = default;
39-
40-
/// \brief Destroy the RawTensor and release exclusive resources.
41-
virtual ~RawTensor() {
42-
if (!data_.empty()) {
43-
data_deleter_();
44-
}
45-
}
46-
47-
public:
48-
/// \brief Returns the name of the class for type traits.
49-
/// \return The name of the class.
50-
static const char* name() { return "RawTensor"; }
51-
52-
template <typename T>
53-
T& Get() const {
54-
PADDLE_ENFORCE_EQ(data_.empty(),
55-
false,
56-
common::errors::PreconditionNotMet(
57-
"The data in RawTensor is empty. Please set data "
58-
"before using it."));
59-
60-
try {
61-
return *(paddle::any_cast<T*>(data_));
62-
} catch (paddle::bad_any_cast&) {
63-
PADDLE_THROW(common::errors::InvalidArgument(
64-
"Invalid data type error, expected %s, actual %s.",
65-
typeid(T).name(),
66-
data_type_.name()));
67-
}
68-
}
69-
70-
template <typename T>
71-
T* GetMutable() {
72-
if (!data_.empty()) {
73-
try {
74-
return paddle::any_cast<T*>(data_);
75-
} catch (paddle::bad_any_cast&) {
76-
PADDLE_THROW(common::errors::InvalidArgument(
77-
"Invalid data type error, expected %s, actual %s.",
78-
typeid(T).name(),
79-
data_type_.name()));
80-
}
81-
}
82-
T* created_data = new T();
83-
data_ = created_data;
84-
data_deleter_ = [created_data]() { delete created_data; };
85-
data_type_ = std::type_index(typeid(T));
86-
return created_data;
87-
}
88-
89-
template <typename T>
90-
bool IsType() const {
91-
return std::type_index(typeid(T)) == data_type_;
92-
}
93-
94-
private:
95-
paddle::any data_;
96-
std::function<void(void)> data_deleter_ = []() {};
97-
std::type_index data_type_ = std::type_index(typeid(void));
98-
};
99-
100-
} // namespace framework
101-
} // namespace paddle
16+
#include "paddle/phi/core/framework/raw_tensor.h"

paddle/fluid/framework/string_array.h

+1-116
Original file line numberDiff line numberDiff line change
@@ -14,119 +14,4 @@ limitations under the License. */
1414

1515
#pragma once
1616

17-
#include <codecvt>
18-
#include <iostream>
19-
#include <locale>
20-
#include <string>
21-
#include <unordered_map>
22-
#include <vector>
23-
#include "paddle/fluid/framework/phi_tensor_base_vector.h"
24-
#include "paddle/phi/core/dense_tensor.h"
25-
#include "paddle/phi/core/extended_tensor.h"
26-
27-
namespace paddle {
28-
namespace framework {
29-
30-
// Note(YuanRisheng): Vocab is mainly used for faster_tokenizer_op and we don't
31-
// recommend widely use it. Because faster_tokenizer_op may be deleted in the
32-
// future and this class will be deleted.
33-
34-
class Vocab : public phi::ExtendedTensor,
35-
public phi::TypeInfoTraits<phi::TensorBase, Vocab> {
36-
public:
37-
Vocab() = default;
38-
39-
Vocab(Vocab&& other) = default;
40-
41-
Vocab(const Vocab& other) = default;
42-
43-
Vocab& operator=(const Vocab& other) = default;
44-
45-
Vocab& operator=(Vocab&& other) = default;
46-
47-
Vocab& operator=(
48-
const std::unordered_map<std::wstring, std::int32_t>& other) {
49-
this->data_ = other;
50-
return *this;
51-
}
52-
53-
/// \brief Destroy the Vocab and release exclusive resources.
54-
virtual ~Vocab() = default;
55-
56-
public:
57-
/// \brief Returns the name of the class for type traits.
58-
/// \return The name of the class.
59-
static const char* name() { return "Vocab"; }
60-
61-
size_t size() const { return data_.size(); }
62-
63-
void clear() { data_.clear(); }
64-
65-
void emplace(const std::wstring& key, std::int32_t value) {
66-
data_.emplace(key, value);
67-
}
68-
69-
std::int32_t at(const std::wstring& key) { return data_.at(key); }
70-
71-
std::int32_t at(const std::wstring& key) const { return data_.at(key); }
72-
73-
std::unordered_map<std::wstring, std::int32_t>::iterator find(
74-
const std::wstring& key) {
75-
return data_.find(key);
76-
}
77-
78-
std::unordered_map<std::wstring, std::int32_t>::const_iterator find(
79-
const std::wstring& key) const {
80-
return data_.find(key);
81-
}
82-
83-
std::unordered_map<std::wstring, std::int32_t>::iterator begin() {
84-
return data_.begin();
85-
}
86-
87-
std::unordered_map<std::wstring, std::int32_t>::const_iterator begin() const {
88-
return data_.begin();
89-
}
90-
91-
std::unordered_map<std::wstring, std::int32_t>::iterator end() {
92-
return data_.end();
93-
}
94-
95-
std::unordered_map<std::wstring, std::int32_t>::const_iterator end() const {
96-
return data_.end();
97-
}
98-
99-
private:
100-
std::unordered_map<std::wstring, std::int32_t> data_;
101-
};
102-
103-
// Note(YuanRisheng): PhiVector is essentially a vector that only used for PHI
104-
// Kernel. It can be used when you define a non-tensor type that needs to be
105-
// stored in a vector as PHI kernel argument.
106-
107-
template <>
108-
struct PhiVectorType<std::string> {
109-
const char* type_name = "PhiVectorString";
110-
};
111-
112-
using String = std::string;
113-
using Strings = PhiVector<std::string>;
114-
115-
// Convert the std::string type to the std::string type.
116-
bool ConvertStrToWstr(const std::string& src, std::wstring* res);
117-
// Convert the std::wstring type to the std::string type.
118-
void ConvertWstrToStr(const std::wstring& src, std::string* res);
119-
// Normalization Form Canonical Decomposition.
120-
void NFD(const std::string& s, std::string* ret);
121-
122-
// Write the data which is type of
123-
// std::unordered_map<td::string, int32_t> to ostream.
124-
void StringMapToStream(std::ostream& os,
125-
const std::unordered_map<std::string, int32_t>& data);
126-
127-
// Read the data which is type of
128-
// std::unordered_map<td::string, int32_t> from istream.
129-
void StringMapFromStream(std::istream& is,
130-
std::unordered_map<std::string, int32_t>* data);
131-
} // namespace framework
132-
} // namespace paddle
17+
#include "paddle/phi/core/vocab/string_array.h"

paddle/fluid/framework/tensor_ref_array.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414

1515
#pragma once
1616

17-
#include "paddle/fluid/framework/phi_tensor_base_vector.h"
18-
19-
namespace paddle {
20-
namespace framework {
17+
#include "paddle/phi/core/vocab/phi_tensor_base_vector.h"
2118

19+
namespace phi {
2220
template <>
23-
struct PhiVectorType<const framework::Variable*> {
21+
struct PhiVectorType<const paddle::framework::Variable*> {
2422
const char* type_name = "VariableRefArray";
2523
};
24+
} // namespace phi
25+
26+
namespace paddle {
27+
namespace framework {
2628

2729
using VariableRefArray = PhiVector<const framework::Variable*>;
2830

paddle/fluid/framework/type_info.cc

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ bool TypeInfoTraits<BaseT, DerivedT>::classof(const BaseT* obj) {
3939
}
4040

4141
template class TypeInfoTraits<phi::TensorBase, paddle::framework::RawTensor>;
42-
template class TypeInfoTraits<phi::TensorBase, paddle::framework::Vocab>;
43-
template class TypeInfoTraits<phi::TensorBase, paddle::framework::Strings>;
4442
template class TypeInfoTraits<phi::TensorBase, paddle::framework::FeedList>;
4543
template class TypeInfoTraits<phi::TensorBase, egr::VariableCompatTensor>;
4644
template class TypeInfoTraits<phi::TensorBase, paddle::prim::DescTensor>;

paddle/fluid/imperative/prepared_operator.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "paddle/phi/core/dense_tensor.h"
3535
#include "paddle/phi/core/kernel_context.h"
3636
#include "paddle/phi/core/selected_rows.h"
37+
#include "paddle/phi/core/vocab/string_array.h"
3738

3839
COMMON_DECLARE_bool(use_mkldnn);
3940

@@ -307,8 +308,14 @@ void BuildDygraphPhiKernelContext(const phi::KernelSignature& kernel_signature,
307308
kernel_ctx->AssignInputRange(std::make_pair(start_idx, end_idx), i);
308309
continue;
309310
} else if (input_defs[i].type_index ==
310-
std::type_index(typeid(
311-
paddle::optional<std::vector<const phi::DenseTensor*>>))) {
311+
std::type_index(
312+
typeid(paddle::optional<phi::ExtendedTensor>)) ||
313+
input_defs[i].type_index ==
314+
std::type_index(typeid(paddle::optional<phi::Strings>)) ||
315+
input_defs[i].type_index ==
316+
std::type_index(
317+
typeid(paddle::optional<
318+
std::vector<const phi::DenseTensor*>>))) {
312319
kernel_ctx->EmplaceBackInputWithoutSetRange(nullptr);
313320
auto end_idx = start_idx + 1;
314321
kernel_ctx->AssignInputRange(std::make_pair(start_idx, end_idx), i);
@@ -338,6 +345,12 @@ void BuildDygraphPhiKernelContext(const phi::KernelSignature& kernel_signature,
338345
} else if (var.template IsType<phi::TensorArray>()) {
339346
tensor_in = &(var.template Get<phi::TensorArray>());
340347
kernel_ctx->EmplaceBackInputWithoutSetRange(tensor_in);
348+
} else if (var.template IsType<phi::Vocab>()) {
349+
tensor_in = &(var.template Get<phi::Vocab>());
350+
kernel_ctx->EmplaceBackInputWithoutSetRange(tensor_in);
351+
} else if (var.template IsType<phi::Strings>()) {
352+
tensor_in = &(var.template Get<phi::Strings>());
353+
kernel_ctx->EmplaceBackInputWithoutSetRange(tensor_in);
341354
} else {
342355
PADDLE_THROW(common::errors::Unimplemented(
343356
"Unsupported input `%s` type when call pt kernel.",

paddle/fluid/operators/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ op_library(generated_op UNITY SRCS generated_op1.cc generated_op2.cc generated_o
8181
op_library(run_program_op DEPS executor_cache ${OP_HEADER_DEPS})
8282
target_link_libraries(run_program_op phi common)
8383
op_library(quantize_linear_op DEPS phi common)
84-
op_library(save_combine_op DEPS string_array phi common)
85-
op_library(load_combine_op DEPS string_array)
84+
op_library(save_combine_op DEPS phi)
85+
op_library(load_combine_op DEPS phi)
8686

8787
op_library(activation_op SRCS activation_op.cc DEPS ${OP_HEADER_DEPS})
8888

paddle/fluid/operators/load_combine_op.cc

-11
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,3 @@ namespace ops = paddle::operators; // NOLINT
8181
REGISTER_OPERATOR(load_combine,
8282
ops::LoadCombineOp,
8383
ops::LoadCombineOpProtoMaker);
84-
85-
PD_REGISTER_STRUCT_KERNEL(load_combine,
86-
CPU,
87-
ALL_LAYOUT,
88-
ops::LoadCombineOpKernel,
89-
float,
90-
double,
91-
phi::dtype::bfloat16,
92-
int,
93-
int8_t,
94-
int64_t) {}

paddle/fluid/operators/load_combine_op.cu

-26
This file was deleted.

0 commit comments

Comments
 (0)