TorchLean API

NN.Spec.Core.Pointwise

Pointwise operators #

PyTorch's core ATen vocabulary contains many pointwise operators, such as neg, div, pow, rsqrt, erf, gelu and clamp_min. They share one shape rule: every operand and the result have the same shape. Graphs therefore represent them as one operation family whose operator is data, and PointwiseOp lists the operators of that family together with the static attributes PyTorch passes them, such as the rounding mode of torch.div.

What an operator computes depends on the scalar type. A scalar dictionary lists the operators it implements in Context.pointwise, as a PointwiseTable. Each entry is a total function that returns the result or a reason why the scalar type has none; over the reals, for example, a zero divisor has no quotient. An operator missing from a table is unsupported for that scalar type, and evaluators report it instead of approximating it.

References #

Rounding applied to a quotient, as the rounding_mode argument of torch.div.

  • none : DivRounding

    True division, PyTorch's rounding_mode=None.

  • trunc : DivRounding

    Round the quotient toward zero, rounding_mode="trunc".

  • floor : DivRounding

    Round the quotient toward negative infinity, rounding_mode="floor".

Instances For
    @[instance_reducible]

    The formula selected by the approximate argument of torch.nn.functional.gelu.

    Instances For

      Pointwise operators represented by the graph family NN.IR.OpKind.pointwise.

      Instances For
        @[instance_reducible]
        Instances For

          Number of tensor operands.

          Instances For

            Every operator takes at least one operand.

            Short operator name without attributes, for grouping diagnostics.

            Instances For

              Operator name with its attribute, for diagnostics. Artifact codecs define their own spelling.

              Instances For

                Every operator with every attribute value, in declaration order.

                Instances For

                  The enumeration is complete.

                  @[reducible, inline]
                  abbrev Spec.PointwiseFn (α : Type) (arity : Nat) :

                  The meaning of an operator with arity operands at the scalar type α.

                  The function receives the operands in order and returns the result, or the reason why the scalar type has no result for them.

                  Instances For
                    def Spec.PointwiseFn.unary {α : Type} (f : α → Except String α) :

                    A meaning with one operand.

                    Instances For
                      def Spec.PointwiseFn.binary {α : Type} (f : α → α → Except String α) :

                      A meaning with two operands, in order.

                      Instances For
                        @[reducible, inline]

                        The pointwise operators a scalar type implements, each with its meaning.

                        Instances For
                          def Spec.divFloorSchedule {α : Type} [Zero α] [One α] [Add α] [Sub α] [Div α] [LT α] [DecidableRel fun (x1 x2 : α) => x1 < x2] [BEq α] (fmod : α → α → α) (floor signedZero : α → α) (half a b : α) :
                          α

                          PyTorch's flooring division, c10::div_floor_floating, over the operations it uses.

                          fmod is C's truncating remainder, floor rounds toward negative infinity, and signedZero q is zero with the sign of q. A zero divisor returns the quotient itself. Otherwise the remainder corrects the quotient, as Python's // does, and the final comparison with half repairs a quotient that rounded across an integer. A binary format runs this schedule with its rounded operations; over the reals it computes ⌊a / b⌋.

                          Instances For