Caffe2 - C++ API
A deep learning, cross platform ML framework
clip_tensor_op.cc
1 #include "caffe2/sgd/clip_tensor_op.h"
2 
3 namespace caffe2 {
4 
5 REGISTER_CPU_OPERATOR(ClipTensorByScaling, ClipTensorByScalingOp<CPUContext>);
6 OPERATOR_SCHEMA(ClipTensorByScaling)
7  .NumInputs(2, 3)
8  .NumOutputs(1)
9  .AllowInplace({{0, 0}})
10  .SetDoc(R"DOC(
11  Clips the input tensor by scaling based on the input value and the threshold.
12  The value is usually the (pre-computed) norm of the tensor. If the value is
13  larger than the threshold, scaling would be performed in this way:
14 
15  tensor *= (threshold / value).
16 
17  An optional input called additional_threshold can be provided which
18  will scale the original threshold before it is used. That is,
19  the final threshold will become threshold * additional_threshold.
20  This op could be used for gradient clipping.
21 )DOC")
22  .Input(0, "input_tensor", "Tensor of floats to be clipped.")
23  .Input(1, "val", "Value to be compared against the threshold")
24  .Input(
25  2,
26  "additional_threshold",
27  "An optional additonal threshold to scale the orignal threshold")
28  .Arg("threshold", "Threshold to determine whether to scale down the tensor")
29  .Output(
30  0,
31  "clipped",
32  "Tensor of floats, which is the same size as the input tensor, "
33  "representing the clipped tensor.");
34 
35 SHOULD_NOT_DO_GRADIENT(ClipTensorByScaling);
36 }; // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13