|View source on GitHub|
Class outlining the default Tracing Protocol for Scalarizer.
tf_agents.bandits.multi_objective.multi_objective_scalarizer.ScalarizerTraceType( value )
If included as an argument, corresponding tf.function will always retrace for each usage.
Derived classes can override this behavior by specifying their own Tracing Protocol.
is_subtype_of( _ )
Returns True if
self is a subtype of
tf.function uses subtyping for dispatch:
a.is_subtype_of(b) is True, then an argument of
a can be used as argument to a
ConcreteFunction traced with an
||A TraceType object to be compared against.|
class Dimension(TraceType): def __init__(self, value: Optional[int]): self.value = value def is_subtype_of(self, other): # Either the value is the same or other has a generalized value that # can represent any specific ones. return (self.value == other.value) or (other.value is None)
most_specific_common_supertype( _ )
Returns the most specific supertype of
others, if exists.
TraceType is a supertype of
others, that is,
they are all subtypes (see
is_subtype_of) of it.
It is also most specific, that is, there it has no subtype that is also
a common supertype of
others have no common supertype, this returns
||A sequence of TraceTypes.|
class Dimension(TraceType): def __init__(self, value: Optional[int]): self.value = value def most_specific_common_supertype(self, other): # Either the value is the same or other has a generalized value that # can represent any specific ones. if self.value == other.value: return self.value else: return Dimension(None)
placeholder_value( placeholder_context=None )
Creates a placeholder for tracing.
tf.funcion traces with the placeholder value rather than the actual value. For example, a placeholder value can represent multiple different actual values. This means that the trace generated with that placeholder value is more general and reusable which saves expensive retracing.
Fruit example shared above, implementing:
class FruitTraceType: def placeholder_value(self, placeholder_context): return Fruit()
instructs tf.function to trace with the
instead of the actual
Mango() objects when it receives a
get_mixed_flavor(Apple(), Mango()). For example, Tensor arguments
are replaced with Tensors of similar shape and dtype, output from
a tf.Placeholder op.
More generally, placeholder values are the arguments of a tf.function, as seen from the function's body:
@tf.function def foo(x): # Here `x` is be the placeholder value ... foo(x) # Here `x` is the actual value
__eq__( _ )