Skip to content

Commit 354d3a9

Browse files
tfx-copybaratensorflow-extended-team
authored and
tensorflow-extended-team
committed
Rename component "name" argument to "instance_name" and remove "component_name".
PiperOrigin-RevId: 266254963
1 parent b536325 commit 354d3a9

File tree

31 files changed

+144
-157
lines changed

31 files changed

+144
-157
lines changed

RELEASE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@
115115
equivalent overriding functionality is now available by specifying optional
116116
keyword arguments (see each component class definition for details).
117117
* The optional arguments "executor" and "unique_name" of component classes
118-
have been uniformly renamed to "executor_spec" and "name", respectively.
119-
The "driver" optional argument of component classes is no longer available:
118+
have been uniformly renamed to "executor_spec" and "instance_name",
119+
respectively.
120+
* The "driver" optional argument of component classes is no longer available:
120121
users who need to override the driver for a component should subclass the
121122
component and override the DRIVER_CLASS field.
122123
* The `example_gen.component.ExampleGen` class has been refactored into the

tfx/components/base/base_component.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,11 @@ class BaseComponent(with_metaclass(abc.ABCMeta, object)):
5555
this component (optional, defaults to base_driver.BaseDriver).
5656
"""
5757

58-
# Subclasses may optionally override this component name property, which
59-
# would otherwise default to the component class name. This is used for
60-
# tracking component instances in pipelines and display in the UI.
61-
COMPONENT_NAME = None
6258
# Subclasses must override this property (by specifying a types.ComponentSpec
6359
# class, e.g. "SPEC_CLASS = MyComponentSpec").
6460
SPEC_CLASS = _abstract_property()
6561
# Subclasses must also override the executor spec.
62+
#
6663
# Note: EXECUTOR_CLASS has been replaced with EXECUTOR_SPEC. A custom
6764
# component's existing executor class definition "EXECUTOR_CLASS = MyExecutor"
6865
# should be replaced with "EXECUTOR_SPEC = ExecutorClassSpec(MyExecutor).
@@ -75,21 +72,16 @@ def __init__(
7572
self,
7673
spec: types.ComponentSpec,
7774
custom_executor_spec: Optional[executor_spec.ExecutorSpec] = None,
78-
name: Optional[Text] = None,
79-
component_name: Optional[Text] = None):
75+
instance_name: Optional[Text] = None):
8076
"""Initialize a component.
8177
8278
Args:
8379
spec: types.ComponentSpec object for this component instance.
8480
custom_executor_spec: Optional custom executor spec overriding the default
8581
executor specified in the component attribute.
86-
name: Optional unique identifying name for this instance of the component
87-
in the pipeline. Required if two instances of the same component is used
88-
in the pipeline.
89-
component_name: Optional component name override for this instance of the
90-
component. This will override the class-level COMPONENT_NAME attribute
91-
and the name of the class (which would otherwise be used as the
92-
component name).
82+
instance_name: Optional unique identifying name for this instance of the
83+
component in the pipeline. Required if two instances of the same
84+
component is used in the pipeline.
9385
"""
9486
self.spec = spec
9587
if custom_executor_spec:
@@ -99,10 +91,8 @@ def __init__(
9991
'ExecutorSpec') % (custom_executor_spec, self.__class__))
10092
self.executor_spec = (custom_executor_spec or self.__class__.EXECUTOR_SPEC)
10193
self.driver_class = self.__class__.DRIVER_CLASS
102-
self.component_name = (
103-
component_name or self.__class__.COMPONENT_NAME or
104-
self.__class__.__name__)
105-
self.name = name
94+
# TODO(b/139540680): consider making instance_name private.
95+
self.instance_name = instance_name
10696
self._upstream_nodes = set()
10797
self._downstream_nodes = set()
10898
self._validate_component_class()
@@ -141,10 +131,10 @@ def _validate_spec(self, spec):
141131
(self.__class__, self.__class__.SPEC_CLASS, spec))
142132

143133
def __repr__(self):
144-
return ('%s(spec: %s, executor_spec: %s, driver_class: %s, name: %s, '
145-
'inputs: %s, outputs: %s)') % (
134+
return ('%s(spec: %s, executor_spec: %s, driver_class: %s, '
135+
'component_id: %s, inputs: %s, outputs: %s)') % (
146136
self.__class__.__name__, self.spec, self.executor_spec,
147-
self.driver_class, self.name, self.inputs, self.outputs)
137+
self.driver_class, self.component_id, self.inputs, self.outputs)
148138

149139
@property
150140
def component_type(self) -> Text:
@@ -166,23 +156,24 @@ def exec_properties(self) -> Dict[Text, Any]:
166156
# we will have two component level keys:
167157
# - component_type: the path of the python executor or the image uri of the
168158
# executor.
169-
# - component_id: <component_name>.<unique_name>
159+
# - component_id: <component_class_name>.<unique_name>
170160
@property
171161
def component_id(self):
172-
"""Component id.
162+
"""Component id, unique across all component instances in a pipeline.
173163
174164
If unique name is available, component_id will be:
175-
<component_name>.<unique_name>
165+
<component_class_name>.<instance_name>
176166
otherwise, component_id will be:
177-
<component_name>
167+
<component_class_name>
178168
179169
Returns:
180170
component id.
181171
"""
182-
if self.name:
183-
return '{}.{}'.format(self.component_name, self.name)
172+
component_class_name = self.__class__.__name__
173+
if self.instance_name:
174+
return '{}.{}'.format(component_class_name, self.instance_name)
184175
else:
185-
return self.component_name
176+
return component_class_name
186177

187178
@property
188179
def upstream_nodes(self):

tfx/components/base/base_component_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class _BasicComponentSpec(types.ComponentSpec):
4343

4444
class _BasicComponent(base_component.BaseComponent):
4545

46-
COMPONENT_NAME = 'MyBasicComponent'
4746
SPEC_CLASS = _BasicComponentSpec
4847
EXECUTOR_SPEC = executor_spec.ExecutorClassSpec(base_executor.BaseExecutor)
4948

@@ -63,7 +62,7 @@ class ComponentTest(tf.test.TestCase):
6362
def testComponentBasic(self):
6463
input_channel = types.Channel(type_name='InputType')
6564
component = _BasicComponent(folds=10, input=input_channel)
66-
self.assertEqual(component.component_name, 'MyBasicComponent')
65+
self.assertEqual(component.component_id, '_BasicComponent')
6766
self.assertIs(input_channel, component.inputs.input)
6867
self.assertIsInstance(component.outputs.output, types.Channel)
6968
self.assertEqual(component.outputs.output.type_name, 'OutputType')

tfx/components/evaluator/component.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(
7575
feature_slicing_spec: Optional[evaluator_pb2.FeatureSlicingSpec] = None,
7676
output: Optional[types.Channel] = None,
7777
model: Optional[types.Channel] = None,
78-
name: Optional[Text] = None):
78+
instance_name: Optional[Text] = None):
7979
"""Construct an Evaluator component.
8080
8181
Args:
@@ -89,12 +89,12 @@ def __init__(
8989
instance that describes how Evaluator should slice the data.
9090
output: Channel of `ModelEvalPath` to store the evaluation results.
9191
model: Future replacement of the `model_exports` argument.
92-
name: Name assigned to this specific instance of Evaluator. Required
93-
only if multiple Evaluator components are declared in the same pipeline.
92+
instance_name: Optional name assigned to this specific instance of
93+
Evaluator. Required only if multiple Evaluator components are declared
94+
in the same pipeline.
9495
9596
Either `model_exports` or `model` must be present in the input arguments.
9697
"""
97-
9898
model_exports = model_exports or model
9999
output = output or types.Channel(
100100
type=standard_artifacts.ModelEvaluation,
@@ -105,4 +105,4 @@ def __init__(
105105
feature_slicing_spec=(feature_slicing_spec or
106106
evaluator_pb2.FeatureSlicingSpec()),
107107
output=output)
108-
super(Evaluator, self).__init__(spec=spec, name=name)
108+
super(Evaluator, self).__init__(spec=spec, instance_name=instance_name)

tfx/components/example_gen/big_query_example_gen/component.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self,
4141
input_config: Optional[example_gen_pb2.Input] = None,
4242
output_config: Optional[example_gen_pb2.Output] = None,
4343
example_artifacts: Optional[types.Channel] = None,
44-
name: Optional[Text] = None):
44+
instance_name: Optional[Text] = None):
4545
"""Constructs a BigQueryExampleGen component.
4646
4747
Args:
@@ -55,8 +55,8 @@ def __init__(self,
5555
size 2:1.
5656
example_artifacts: Optional channel of 'ExamplesPath' for output train and
5757
eval examples.
58-
name: Optional unique name. Necessary if multiple BigQueryExampleGen
59-
components are declared in the same pipeline.
58+
instance_name: Optional unique instance name. Necessary if multiple
59+
BigQueryExampleGen components are declared in the same pipeline.
6060
6161
Raises:
6262
RuntimeError: Only one of query and input_config should be set.
@@ -68,4 +68,4 @@ def __init__(self,
6868
input_config=input_config,
6969
output_config=output_config,
7070
example_artifacts=example_artifacts,
71-
name=name)
71+
instance_name=instance_name)

tfx/components/example_gen/component.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ def __init__(self,
5757
input_config: example_gen_pb2.Input,
5858
output_config: Optional[example_gen_pb2.Output] = None,
5959
custom_config: Optional[example_gen_pb2.CustomConfig] = None,
60-
component_name: Optional[Text] = 'ExampleGen',
6160
example_artifacts: Optional[types.Channel] = None,
62-
name: Optional[Text] = None):
61+
instance_name: Optional[Text] = None):
6362
"""Construct an QueryBasedExampleGen component.
6463
6564
Args:
@@ -73,13 +72,10 @@ def __init__(self,
7372
custom_config: An
7473
[example_gen_pb2.CustomConfig](https://github.com/tensorflow/tfx/blob/master/tfx/proto/example_gen.proto)
7574
instance, providing custom configuration for ExampleGen.
76-
component_name: Name of the component. This should be unique per
77-
component class. Default to 'ExampleGen' and may be overwritten by
78-
subclasses.
7975
example_artifacts: Channel of 'ExamplesPath' for output train and
8076
eval examples.
81-
name: Unique name. Required only if multiple ExampleGen components are
82-
declared in the same pipeline.
77+
instance_name: Optional unique instance name. Required only if multiple
78+
ExampleGen components are declared in the same pipeline.
8379
"""
8480
# Configure outputs.
8581
output_config = output_config or utils.make_default_output_config(
@@ -94,7 +90,8 @@ def __init__(self,
9490
output_config=output_config,
9591
custom_config=custom_config,
9692
examples=example_artifacts)
97-
super(_QueryBasedExampleGen, self).__init__(spec=spec, name=name)
93+
super(_QueryBasedExampleGen, self).__init__(
94+
spec=spec, instance_name=instance_name)
9895

9996

10097
class FileBasedExampleGen(base_component.BaseComponent):
@@ -127,11 +124,10 @@ def __init__(
127124
input_config: Optional[example_gen_pb2.Input] = None,
128125
output_config: Optional[example_gen_pb2.Output] = None,
129126
custom_config: Optional[example_gen_pb2.CustomConfig] = None,
130-
component_name: Optional[Text] = 'ExampleGen',
131127
example_artifacts: Optional[types.Channel] = None,
132128
custom_executor_spec: Optional[executor_spec.ExecutorSpec] = None,
133129
input: Optional[types.Channel] = None, # pylint: disable=redefined-builtin
134-
name: Optional[Text] = None):
130+
instance_name: Optional[Text] = None):
135131
"""Construct a FileBasedExampleGen component.
136132
137133
Args:
@@ -147,16 +143,13 @@ def __init__(
147143
'eval' with size 2:1.
148144
custom_config: An optional example_gen_pb2.CustomConfig instance,
149145
providing custom configuration for executor.
150-
component_name: Name of the component, should be unique per component
151-
class. Do not use -- will be deprecated in a future release.
152146
example_artifacts: Channel of 'ExamplesPath' for output train and
153147
eval examples.
154148
custom_executor_spec: Optional custom executor spec overriding the default
155149
executor spec specified in the component attribute.
156150
input: Future replacement of the 'input_base' argument.
157-
name: Name assigned to this specific instance of FileBasedExampleGen.
158-
Required only if multiple FileBasedExampleGen components are declared in
159-
the same pipeline.
151+
instance_name: Optional unique instance name. Required only if multiple
152+
ExampleGen components are declared in the same pipeline.
160153
161154
Either `input_base` or `input` must be present in the input arguments.
162155
"""
@@ -177,4 +170,6 @@ def __init__(
177170
custom_config=custom_config,
178171
examples=example_artifacts)
179172
super(FileBasedExampleGen, self).__init__(
180-
spec=spec, custom_executor_spec=custom_executor_spec, name=name)
173+
spec=spec,
174+
custom_executor_spec=custom_executor_spec,
175+
instance_name=instance_name)

tfx/components/example_gen/component_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ def __init__(self,
4444
input_config,
4545
output_config=None,
4646
example_artifacts=None,
47-
name=None):
47+
instance_name=None):
4848
super(TestQueryBasedExampleGenComponent, self).__init__(
4949
input_config=input_config,
5050
output_config=output_config,
5151
example_artifacts=example_artifacts,
52-
name=name)
52+
instance_name=instance_name)
5353

5454

5555
class TestFileBasedExampleGenComponent(component.FileBasedExampleGen):
@@ -61,13 +61,13 @@ def __init__(self,
6161
input_config=None,
6262
output_config=None,
6363
example_artifacts=None,
64-
name=None):
64+
instance_name=None):
6565
super(TestFileBasedExampleGenComponent, self).__init__(
6666
input_base=input_base,
6767
input_config=input_config,
6868
output_config=output_config,
6969
example_artifacts=example_artifacts,
70-
name=name)
70+
instance_name=instance_name)
7171

7272

7373
class ComponentTest(tf.test.TestCase):

tfx/components/example_gen/csv_example_gen/component.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self,
4141
output_config: Optional[example_gen_pb2.Output] = None,
4242
example_artifacts: Optional[types.Channel] = None,
4343
input: Optional[types.Channel] = None, # pylint: disable=redefined-builtin
44-
name: Optional[Text] = None):
44+
instance_name: Optional[Text] = None):
4545
"""Construct a CsvExampleGen component.
4646
4747
Args:
@@ -56,13 +56,13 @@ def __init__(self,
5656
example_artifacts: Optional channel of 'ExamplesPath' for output train and
5757
eval examples.
5858
input: Forwards compatibility alias for the 'input_base' argument.
59-
name: Optional unique name. Necessary if multiple CsvExampleGen components
60-
are declared in the same pipeline.
59+
instance_name: Optional unique instance name. Necessary if multiple
60+
CsvExampleGen components are declared in the same pipeline.
6161
"""
6262
super(CsvExampleGen, self).__init__(
6363
input_base=input_base,
6464
input_config=input_config,
6565
output_config=output_config,
6666
example_artifacts=example_artifacts,
6767
input=input,
68-
name=name)
68+
instance_name=instance_name)

tfx/components/example_gen/custom_executors/avro_component_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def testRun(self, mock_publisher):
6262
input_base=external_input(self.avro_dir_path),
6363
input_config=self.input_config,
6464
output_config=self.output_config,
65-
name='AvroExampleGenComponent')
65+
instance_name='AvroExampleGen')
6666

6767
output_data_dir = os.path.join(
6868
os.environ.get('TEST_UNDECLARED_OUTPUTS_DIR', self.get_temp_dir()),
@@ -92,7 +92,7 @@ def testRun(self, mock_publisher):
9292
mock_publisher.return_value.publish_execution.assert_called_once()
9393

9494
# Get output paths.
95-
component_id = '.'.join([example_gen.component_name, example_gen.name])
95+
component_id = example_gen.component_id
9696
output_path = os.path.join(pipeline_root, component_id, 'examples/1')
9797
train_examples = standard_artifacts.Examples(split='train')
9898
train_examples.uri = os.path.join(output_path, 'train')

tfx/components/example_gen/custom_executors/parquet_component_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def testRun(self, mock_publisher):
6363
input_base=external_input(self.parquet_dir_path),
6464
input_config=self.input_config,
6565
output_config=self.output_config,
66-
name='parquetExampleGenComponent')
66+
instance_name='ParquetExampleGen')
6767

6868
output_data_dir = os.path.join(
6969
os.environ.get('TEST_UNDECLARED_OUTPUTS_DIR', self.get_temp_dir()),
@@ -93,7 +93,7 @@ def testRun(self, mock_publisher):
9393
mock_publisher.return_value.publish_execution.assert_called_once()
9494

9595
# Get output paths.
96-
component_id = '.'.join([example_gen.component_name, example_gen.name])
96+
component_id = example_gen.component_id
9797
output_path = os.path.join(pipeline_root, component_id, 'examples/1')
9898
train_examples = standard_artifacts.Examples(split='train')
9999
train_examples.uri = os.path.join(output_path, 'train')

tfx/components/example_gen/import_example_gen/component.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self,
4343
output_config: Optional[example_gen_pb2.Output] = None,
4444
example_artifacts: Optional[types.Channel] = None,
4545
input: Optional[types.Channel] = None, # pylint: disable=redefined-builtin
46-
name: Optional[Text] = None):
46+
instance_name: Optional[Text] = None):
4747
"""Construct an ImportExampleGen component.
4848
4949
Args:
@@ -59,13 +59,13 @@ def __init__(self,
5959
example_artifacts: Optional channel of 'ExamplesPath' for output train and
6060
eval examples.
6161
input: Forwards compatibility alias for the 'input_base' argument.
62-
name: Optional unique name. Necessary if multiple ImportExampleGen
63-
components are declared in the same pipeline.
62+
instance_name: Optional unique instance name. Necessary if multiple
63+
ImportExampleGen components are declared in the same pipeline.
6464
"""
6565
super(ImportExampleGen, self).__init__(
6666
input_base=input_base,
6767
input_config=input_config,
6868
output_config=output_config,
6969
example_artifacts=example_artifacts,
7070
input=input,
71-
name=name)
71+
instance_name=instance_name)

0 commit comments

Comments
 (0)