Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TFMA auto-visualization for TFX components in KFP #3111

Merged
merged 9 commits into from
Feb 19, 2020

Conversation

jingzhang36
Copy link
Contributor

@jingzhang36 jingzhang36 commented Feb 19, 2020

We add TFMA auto-visualization for TFX components in KFP.

Note: Widgets in TFMA visualization depend on tfma_widget_js file, which unfortunately doesn't work outside Notebook (as of now). So this PR depends on the work of @Bobgy https://cdn.jsdelivr.net/gh/Bobgy/model-analysis@kfp/tensorflow_model_analysis/notebook/jupyter/js/dist/, which provides a bundle of js files that can support TFMA widgets to work in KFP context.


This change is Reviewable

Copy link
Contributor

@Bobgy Bobgy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jingzhang36 Thanks for the quick change!
There's a minor issue

`slicing_spec = tfma.slicer.SingleSliceSpec(columns=columns)`,
`eval_result = tfma.load_eval_result('${uri}')`,
`slicing_metrics_view = tfma.view.render_slicing_metrics(eval_result, slicing_spec=slicing_spec)`,
`embed_minimal_html('tfma_export.html', views=[slicing_metrics_view], title='Slicing Metrics')`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @rmgogogo mentioned in email, can you adapt as the following:

use io.StringIO instead of 'tfma_export.html'

More info for your reference
https://ipywidgets.readthedocs.io/en/latest/embedding.html#embedding-widgets-in-html-web-pages
(embed_minimal_html method interface) https://github.com/jupyter-widgets/ipywidgets/blob/master/ipywidgets/embed.py#L292

Copy link
Contributor

@Bobgy Bobgy Feb 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note embed_minimal_html accepts a File like object (in addition to file name) as the first argument, I think io.StringIO can be used instead there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Bobgy
Copy link
Contributor

Bobgy commented Feb 19, 2020

Part of #2283

`from IPython.core.display import display, HTML`,
`config_file=tf.io.gfile.GFile('${configFilePath}', 'r')`,
`config=json.loads(config_file.read())`,
`featureKeys=list(filter(lambda x: 'featureKeys' in x, config['evalConfig']['slicingSpecs']))`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move these Python codes to visulization server. please.
You can simply introduce a new enum type for it, cost is not big.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel this is necessary, but if cost is not high, we can do so too.
I'm not familiar with visualization server code, @rmgogogo can you provide a reference for @jingzhang36 ?

Copy link
Contributor Author

@jingzhang36 jingzhang36 Feb 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave a TODO for this. I personally have no preference regarding where the code is place. Just note that the python code is not run on FE even put it here. If we decide to move, we'll move the statistics, schema and the others together.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check the TFDV patch as a reference. The cost is not big. Just need to add a proto enum and a new python file in types/ folder. It would largely help you well format these python codes.

do prefer take a try on that path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO works so that we can catch beta.

@Bobgy
Copy link
Contributor

Bobgy commented Feb 19, 2020

I was thinking about moving my forked branch to gs://ml-pipeline, but I just felt it's fine as a temporary hack. I will try fix the infinite redirection issue instead to improve experience for this.

@Bobgy Bobgy self-assigned this Feb 19, 2020
@Bobgy
Copy link
Contributor

Bobgy commented Feb 19, 2020

Thanks @jingzhang36!
/lgtm
/approve
/hold
for @rmgogogo to confirm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Bobgy

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -311,6 +311,41 @@ export class OutputArtifactLoader {
return buildArtifactViewer(script);
}),
);
const EvaluatorArtifactUris = filterArtifactUrisByType(
'ModelEvaluation',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do a real test via build a container image and edit yaml to put it in a real cluster to see whether it works.
harded coded codes can't be checked without a real test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on my deployment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Bobgy
Copy link
Contributor

Bobgy commented Feb 19, 2020

/unhold
looks like renmin agrees as long as you have tested this
let's merge this

@jingzhang36
Copy link
Contributor Author

/hold cancel

@jingzhang36
Copy link
Contributor Author

/test kubeflow-pipeline-sample-test

@Bobgy
Copy link
Contributor

Bobgy commented Feb 19, 2020

/test kubeflow-pipeline-e2e-test
because head commit has changed, this will be faster to get this in

@Bobgy
Copy link
Contributor

Bobgy commented Feb 19, 2020

/retest

@k8s-ci-robot k8s-ci-robot merged commit d757838 into kubeflow:master Feb 19, 2020
Jeffwan pushed a commit to Jeffwan/pipelines that referenced this pull request Dec 9, 2020
* TFMA basic: rendering slicing metrics

* tfma rendering

* render

* remove out-of-date todos

* FE format

* Use io.StringIO instead of file

* Add comment for context and reference of TFMA widget hack

* Add TODO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants