14template <
typename T,
typename Data_T>
20 if (return_presence_mask_) {
28 const T* l =
lengths.template data<T>();
31 for (
T i = 0; i <
lengths.size(0); ++i) {
32 max_length =
std::max(max_length, l[i]);
35 if (max_length_ != -1) {
36 max_length = max_length_;
43 " PackSegments requires that the sum of the lengths ",
45 " is equal to the first data dimension ",
50 shape[0] = max_length;
55 auto*
out =
static_cast<char*
>(
output->raw_mutable_data(
data.dtype()));
57 bool* presence_mask_data =
nullptr;
58 if (return_presence_mask_) {
60 std::vector<int64_t> presence_shape{
lengths.numel(), max_length};
62 presence_mask_data =
presence_mask->template mutable_data<bool>();
75 if (
output->template IsType<float>()) {
79 output->template mutable_data<float>(),
81 }
else if (
output->template IsType<int32_t>()) {
82 math::Set<int32_t, CPUContext>(
85 output->template mutable_data<int32_t>(),
87 }
else if (
output->template IsType<int64_t>()) {
88 math::Set<int64_t, CPUContext>(
91 output->template mutable_data<int64_t>(),
93 }
else if (
output->template IsType<char>()) {
97 if (return_presence_mask_) {
98 memset(presence_mask_data, (
int)
false,
presence_mask->numel());
103 const auto* d =
static_cast<const char*
>(
data.raw_data());
106 auto len = l[i] <= max_length ? l[i] : max_length;
110 d + block_bytesize *
start,
111 out + block_bytesize * max_length * i);
112 if (return_presence_mask_) {
113 memset(presence_mask_data + max_length * i, (
int)
true,
len);
130template <
typename T,
typename Data_T>
138 if (max_length_ != -1) {
142 "max_length should be equal to the second dimension of the packed segments");
144 const T* l =
lengths.template data<T>();
147 if (max_length_ != -1) {
149 total_l += (
int64_t)(l[i] <= max_length_ ? l[i] : max_length_);
157 shape[0],
lengths.size(0),
"LENGTH should match DATA in dimension 0");
162 auto*
out =
static_cast<char*
>(
output->raw_mutable_data(
data.dtype()));
163 if (!(
data.size(0) &&
data.size(1))) {
168 const auto* d =
static_cast<const char*
>(
data.raw_data());
172 if (max_length_ != -1 && l[i] > max_length_) {
178 d + block_bytesize *
data.size(1) * i,
192 "Map N dim tensor to N+1 dim based on length blob. Sequences that \
193 are shorter than the longest sequence are padded with zeros.")
197 "1-d int/long tensor contains the length in each of the output.")
198 .Input(1,
"tensor",
"N dim Tensor.")
203 "where dim(1) is the max length"
204 ", dim(0) is the batch size.")
208 "2 dim boolean tensor"
209 ", false where packed_tensor is padded, true otherwise.")
210 .Arg(
"max_length",
"The pre-defined max_length for the packed segments")
213 "Padding number in the packed segments. Use true to pad \
214 -infinity, otherwise pad zeros")
216 "return_presence_mask",
217 "bool whether to return presence mask, false by default");
221 .SetDoc(
"Map N+1 dim tensor to N dim based on length blob")
225 "1-d int/long tensor contains the length in each of the input.")
226 .Input(1,
"tensor",
"N+1 dim Tensor.")
227 .Output(0,
"packed_tensor",
"N dim Tensor")
228 .Arg(
"max_length",
"The pre-defined max_length for the packed segments");
236 vector<string>{
I(0),
GO(0)},
237 vector<string>{
GI(1)});
246 "PackSegments",
"", vector<string>{
I(0),
GO(0)}, vector<string>{
GI(1)});
254 "_caffe2::PackSegments("
257 "int max_length = -1, "
258 "bool pad_minf = False, "
259 "bool return_presence_mask = False"
260 ") -> (Tensor packed_tensor, Tensor presence_mask)",
265 "_caffe2::UnpackSegments("
268 "int max_length = -1"
269 ") -> (Tensor packed_tensor)",
#define CAFFE_ENFORCE_GE(x, y,...)
void CopyItemsSameDevice(const caffe2::TypeMeta meta, size_t n, const void *src, void *dst)
vector< OperatorDef > GetGradientDefs() override
vector< OperatorDef > GetGradientDefs() override
GradientMakerBase(const OperatorDef &def, const vector< GradientWrapper > &g_output)
static vector< OperatorDef > SingleGradientDef(const Args &... args)
a helper function to allow one to create one single operator def, which is usually the case for many ...
constexpr Symbol len(static_cast< unique_t >(_keys::aten_len))
C10_EXPORT void Set< char, CPUContext >(const std::int64_t N, const char alpha, char *Y, CPUContext *)
C10_EXPORT void Set< float, CPUContext >(const std::int64_t N, const float alpha, float *Y, CPUContext *)
Copyright (c) 2016-present, Facebook, Inc.
REGISTER_CPU_OPERATOR(ATen, ATenOp< CPUContext >)
CAFFE_ENFORCE_EQ(in.size(), 1, "New shape must not be specified by the input blob and the " "argument `shape` at the same time.")
the other dimension is proportionally scaled Defaults to Whether or not to mirror the image Defaults to Vector of means per color Standard deviation by which to normalize color channels Defaults to Bounding box coordinate Defaults Bounding box coordinate Defaults Bounding box coordinate Defaults Bounding box coordinate Defaults if the input is in Caffe format Defaults to Number of CPU decode transform threads Defaults to Name of the Type of The sizes of any outputs besides the data and shortest side desired for image resize Defaults to[-1, -1] or no random resize desired data
NumInputs(2) .NumOutputs(1) .SetDoc(R"DOC( Broadcast the input tensor to a materialized new tensor using given shape. Broadcast rule is similar to "numpy.array(input) *numpy.ones(shape)" Two corresponding dimensions must have the same or one of them equals to In order to align with PyTorch s shape is allowed to have entries equal which means to preserve the size of the corresponding dimension in shape
d int long tensor contains the length in each of the output N dim Tensor where presence_mask
SparseLengths8BitsRowwiseOp< CPUContext, 0, 1 >::LENGTHS uint8 tensor obtained with Vector with the same sum of elements as the first dimension of DATA Input(3, "scale_bias", "Matrix of floats, each row r_i of which stores a pair " "s_i, b_i -- scale and bias for i-th row") .Output(0
Maximum number of candidates to carry over to next activation step float Tensor sized[max_activation_length, batch_size, alphabet_size] of network optional int vector containing sequence lengths
true SparseLengthsFused4BitRowwiseFakeFP16Op< CPUContext, true >::WEIGHTS uint8 tensor obtained with Vector with the same sum of elements as the first dimension of DATA output
this op outputs a copy of the input tensor where values from the height and width dimensions are moved to the batch dimension After the zero padding is according to the pad both height and width of the input must be divisible by the block_size Only NCHW order is currently supported Github block_size
required base learning rate default used only for inv policy type default sampling rate on iterations default True in alter policy int64_t
false SparseLengthsFused4BitRowwiseFakeFP16Op< CPUContext, false >::LENGTHS DATA
REGISTER_GRADIENT(CTC, GetCTCGradient)
false SparseLengthsFused4BitRowwiseFakeFP16Op< CPUContext, false >::LENGTHS uint8 tensor obtained with LENGTHS
SparseLengths8BitsRowwiseOp< CPUContext, 1, 1 >::LENGTHS uint8 tensor obtained with Integer vector containing indices of the first dimension of DATA for the slices that are being aggregated Matrix of each row r_i of which stores a pair b_i scale and bias for i th row Output(0, "output", "output")
c10::BFloat16 max(c10::BFloat16 a, c10::BFloat16 b)
static void accumulate(std::vector< Variable > &buffer, const size_t pos, Variable &&var)
C10_EXPORT_CAFFE2_OP_TO_C10_CPU(PackSegments, "_caffe2::PackSegments(" "Tensor lengths, " "Tensor tensor, " "int max_length = -1, " "bool pad_minf = False, " "bool return_presence_mask = False" ") -> (Tensor packed_tensor, Tensor presence_mask)", caffe2::PackSegmentsOp< caffe2::CPUContext >)