![]() |
Updates extracts by calling specified model signature functions.
Inherits From: BatchReducibleBatchedDoFnWithModels
, DoFnWithModels
tfma.model_util.ModelSignaturesDoFn(
eval_config: tfma.EvalConfig
,
eval_shared_models: Dict[Text, tfma.types.EvalSharedModel
],
signature_names: Dict[Text, Dict[Text, List[Text]]],
default_signature_names: Optional[List[Text]] = None,
prefer_dict_outputs: bool = True,
tensor_adapter_config: Optional[tensor_adapter.TensorAdapterConfig] = None
)
Args | |
---|---|
eval_config
|
Eval config. |
eval_shared_models
|
Shared model parameters keyed by model name. |
signature_names
|
Names of signature functions to call keyed by the
associated extracts that should be updated and the name of the model
they are associated with. The signature functions may be stored either
in a dict under a signatures attribute or directly as separate named
attributes of the model. If a signature name list is empty then the
default_signatures will be used. If a list entry is empty (None or ''),
then the model itself (or a common default signature for the model -
e.g. 'serving_default') will be used.
|
default_signature_names
|
One or more signature names to use by default when an empty list is used in signature_names. All defaults will be tried, but unlike signature_names it is not an error if a signature is not found. |
prefer_dict_outputs
|
True to convert results from calling a signature function are are not dicts into dicts by using the signature_name as the key. If False, dict outputs that have only one entry will be converted into single output values. For example, it is preferable to store predictions as single output values (unless a multi-output model is used) whereas it is preferrable to always store features as a dict where the output keys represent the feature names. |
tensor_adapter_config
|
Tensor adapter config which specifies how to obtain tensors from the Arrow RecordBatch. |
Child Classes
Methods
default_label
default_label()
default_type_hints
default_type_hints()
display_data
display_data()
Returns the display data associated to a pipeline component.
It should be reimplemented in pipeline components that wish to have static display data.
Returns | |
---|---|
Dict[str, Any]: A dictionary containing key:value pairs.
The value might be an integer, float or string value; a
:class:DisplayDataItem for values that have more data
(e.g. short value, label, url); or a :class:HasDisplayData instance
that has more display data that should be picked up. For example::
{ 'key1': 'string_value', 'key2': 1234, 'key3': 3.14159265, 'key4': DisplayDataItem('apache.org', url='http://apache.org'), 'key5': subComponent } |
finish_bundle
finish_bundle()
Called after a bundle of elements is processed on a worker.
from_callable
@staticmethod
from_callable( fn )
from_runner_api
@classmethod
from_runner_api( fn_proto, context )
Converts from an FunctionSpec to a Fn object.
Prefer registering a urn with its parameter type and constructor.
get_function_arguments
get_function_arguments(
func
)
get_type_hints
get_type_hints()
Gets and/or initializes type hints for this object.
If type hints have not been set, attempts to initialize type hints in this order:
- Using self.default_type_hints().
- Using self.class type hints.
infer_output_type
infer_output_type(
input_type
)
process
process(
element: tfma.types.Extracts
) -> Sequence[tfma.types.Extracts
]
Method to use for processing elements.
This is invoked by DoFnRunner
for each element of a input
PCollection
.
The following parameters can be used as default values on process
arguments to indicate that a DoFn accepts the corresponding parameters. For
example, a DoFn might accept the element and its timestamp with the
following signature::
def process(element=DoFn.ElementParam, timestamp=DoFn.TimestampParam): ...
The full set of parameters is:
DoFn.ElementParam
: element to be processed, should not be mutated.DoFn.SideInputParam
: a side input that may be used when processing.DoFn.TimestampParam
: timestamp of the input element.DoFn.WindowParam
:Window
the input element belongs to.DoFn.TimerParam
: auserstate.RuntimeTimer
object defined by the spec of the parameter.DoFn.StateParam
: auserstate.RuntimeState
object defined by the spec of the parameter.DoFn.KeyParam
: key associated with the element.DoFn.RestrictionParam
: aniobase.RestrictionTracker
will be provided here to allow treatment as a SplittableDoFn
. The restriction tracker will be derived from the restriction provider in the parameter.DoFn.WatermarkEstimatorParam
: a function that can be used to track output watermark of SplittableDoFn
implementations.
Args | |
---|---|
element
|
The element to be processed |
*args
|
side inputs |
**kwargs
|
other keyword arguments. |
Returns | |
---|---|
An Iterable of output elements or None. |
register_pickle_urn
@classmethod
register_pickle_urn( pickle_urn )
Registers and implements the given urn via pickling.
register_urn
@classmethod
register_urn( urn, parameter_type, fn=None )
Registers a urn with a constructor.
For example, if 'beam:fn:foo' had parameter type FooPayload, one could
write RunnerApiFn.register_urn('bean:fn:foo', FooPayload, foo_from_proto)
where foo_from_proto took as arguments a FooPayload and a PipelineContext.
This function can also be used as a decorator rather than passing the
callable in as the final parameter.
A corresponding to_runner_api_parameter method would be expected that returns the tuple ('beam:fn:foo', FooPayload)
setup
setup()
Called to prepare an instance for processing bundles of elements.
This is a good place to initialize transient in-memory resources, such as
network connections. The resources can then be disposed in
DoFn.teardown
.
start_bundle
start_bundle()
Called before a bundle of elements is processed on a worker.
Elements to be processed are split into bundles and distributed to workers. Before a worker calls process() on the first element of its bundle, it calls this method.
teardown
teardown()
Called to use to clean up this instance before it is discarded.
A runner will do its best to call this method on any given instance to prevent leaks of transient resources, however, there may be situations where this is impossible (e.g. process crash, hardware failure, etc.) or unnecessary (e.g. the pipeline is shutting down and the process is about to be killed anyway, so all transient resources will be released automatically by the OS). In these cases, the call may not happen. It will also not be retried, because in such situations the DoFn instance no longer exists, so there's no instance to retry it on.
Thus, all work that depends on input elements, and all externally important
side effects, must be performed in DoFn.process
or
DoFn.finish_bundle
.
to_runner_api
to_runner_api(
context
)
Returns an FunctionSpec encoding this Fn.
Prefer overriding self.to_runner_api_parameter.
to_runner_api_parameter
to_runner_api_parameter(
context
)
unbounded_per_element
@staticmethod
unbounded_per_element()
A decorator on process fn specifying that the fn performs an unbounded amount of work per input element.
with_input_types
with_input_types(
*arg_hints, **kwarg_hints
)
with_output_types
with_output_types(
*arg_hints, **kwarg_hints
)
Class Variables | |
---|---|
DoFnProcessParams | |
DynamicTimerTagParam | |
ElementParam | |
KeyParam | |
PaneInfoParam | |
SideInputParam | |
TimestampParam | |
WindowParam |