tensorflow / tfx

TFX is an end-to-end platform for deploying production ML pipelines
https://tensorflow.org/tfx
Apache License 2.0
2.11k stars 707 forks source link

Issue with `model.tft_layer` when using `custom_config` in `preprocessing_fn`. #4921

Closed intrainepha closed 1 year ago

intrainepha commented 2 years ago

System information

Issue description: I am using Tranform component with arg custom_config, like this:

  transform = tfx.components.Transform(
            module_file=os.path.abspath(self.cfg.transformer_fn),
            examples=example_gen.outputs['examples'],
            schema=schema_gen.outputs['schema'],
            custom_config=self.hyper_params
        )

If i implement preprocessing_fn without custom_config:

def preprocessing_fn(inputs):
    config = Configer(
        os.path.join(__ROOT, "configs", "bert.yaml")
    )
    preprocessor = BertPreprocessor(config)
    outputs = preprocessor.run(inputs)

    return outputs

It all works fine with downstream components.

But when I then implement preprocessing_fn with custom_config:

def preprocessing_fn(inputs, custom_config):
    preprocessor = BertPreprocessor(custom_config)
    outputs = preprocessor.run(inputs)

    return outputs

Transform layer is not working when i want to save model for tf serving, with code below:

    def _get_serve_tf_strings_fn(self, model, tf_transform_output):

        model.tft_layer = tf_transform_output.transform_features_layer()

        @tf.function(input_signature=[
            tf.TensorSpec(shape=[None], dtype=tf.string, name='examples')
        ])
        def serve_tf_examples_fn(text):
            reshaped_text = tf.reshape(text, [-1, 1])
            transformed_features = model.tft_layer({"text": reshaped_text})
            outputs = model(transformed_features)

            return {'outputs': outputs}

        return serve_tf_examples_fn

transformed_features is {}, nothing in it, can not understand what is happening between these two different situations.

jiyongjung0 commented 2 years ago

@iindyk @zoyahav This seems odd. Could you take a look?

singhniraj08 commented 1 year ago

@intrainepha,

Apologies for late reply. Does your pipeline works and transform component executes while passing custom_config to preprocessing_fn? Can you let me which BertPreprocessor you are using while transformation? I will try to replicate the issue on my end. Generally BertPreprocessor expects the configs as dictionary as BertPreprocessor(**custom_config). Please try this out and let us know if you are still facing issues.

Thank you!

github-actions[bot] commented 1 year ago

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] commented 1 year ago

This issue was closed due to lack of activity after being marked stale for past 7 days.

github-actions[bot] commented 1 year ago

Are you satisfied with the resolution of your issue? Yes No