Skip to content

Commit dd86491

Browse files
committed
Cherry-pick: fix(wit): Redirect WIT plugin to LIT (#6343)
1 parent 96ac55f commit dd86491

File tree

14 files changed

+281
-18
lines changed

14 files changed

+281
-18
lines changed

docs/what_if_tool.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Model Understanding with the What-If Tool Dashboard
22

3+
> **Warning**
4+
> This documentation only applies to TensorBoard 2.11 and earlier, as the
5+
> What-If Tool is no longer actively maintained. Please check out the actively
6+
> maintained [Learning Interpretability Tool
7+
> (LIT)](https://pair-code.github.io/lit/) instead.
8+
39
![What-If Tool](./images/what_if_tool.png)
410

511
The What-If Tool (WIT) provides an easy-to-use interface for expanding

tensorboard/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ py_library(
322322
"//tensorboard/plugins/scalar:scalars_plugin",
323323
"//tensorboard/plugins/text:text_plugin",
324324
"//tensorboard/plugins/text_v2:text_v2_plugin",
325+
"//tensorboard/plugins/wit_redirect:wit_redirect_plugin",
325326
],
326327
)
327328

tensorboard/components/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tf_ts_library(
2121
"//tensorboard/plugins/profile_redirect/tf_profile_redirect_dashboard",
2222
"//tensorboard/plugins/scalar/tf_scalar_dashboard",
2323
"//tensorboard/plugins/text/tf_text_dashboard",
24+
"//tensorboard/plugins/wit_redirect/tf_wit_redirect_dashboard",
2425
],
2526
)
2627

tensorboard/components/polymer3_lib.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ import '../plugins/profile_redirect/tf_profile_redirect_dashboard/tf-profile-red
2626
import '../plugins/pr_curve/tf_pr_curve_dashboard/tf-pr-curve-dashboard';
2727
import '../plugins/scalar/tf_scalar_dashboard/tf-scalar-dashboard';
2828
import '../plugins/text/tf_text_dashboard/tf-text-dashboard';
29+
import '../plugins/wit_redirect/tf_wit_redirect_dashboard/tf-wit-redirect-dashboard';
2930
import './polymer3_interop_helper';

tensorboard/default.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from tensorboard.plugins.text_v2 import text_v2_plugin
4848
from tensorboard.plugins.mesh import mesh_plugin
4949
from tensorboard.plugins.npmi import npmi_plugin
50+
from tensorboard.plugins.wit_redirect import wit_redirect_plugin
5051

5152

5253
logger = logging.getLogger(__name__)
@@ -88,6 +89,7 @@ class ExperimentalNpmiPlugin(
8889
mesh_plugin.MeshPlugin,
8990
ExperimentalTextV2Plugin,
9091
ExperimentalNpmiPlugin,
92+
wit_redirect_plugin.WITRedirectPluginLoader,
9193
]
9294

9395

tensorboard/pip_package/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,5 @@ protobuf >= 3.19.6
3030
requests >= 2.21.0, < 3
3131
setuptools >= 41.0.0 # Note: provides pkg_resources as well as setuptools
3232
tensorboard-data-server >= 0.7.0, < 0.8.0
33-
tensorboard-plugin-wit >= 1.6.0
3433
werkzeug >= 1.0.1
3534
wheel >= 0.26
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# What-If Tool
22

3+
> **Warning**
4+
> The What-If Tool is no longer actively maintained. Please use the actively
5+
> maintained [Learning Interpretability Tool (LIT)](https://pair-code.github.io/lit/)
6+
> instead.
7+
38
The What-If Tool code and documentation has moved to https://github.com/pair-code/what-if-tool.
49

510
The What-If Tool TensorBoard plugin has been converted to a dynamic plugin, through the tensorboard-plugin-wit pip package.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Description:
2+
# Plugin with installation instructions for dynamic interpretability plugin
3+
4+
package(default_visibility = ["//tensorboard:internal"])
5+
6+
licenses(["notice"])
7+
8+
py_library(
9+
name = "wit_redirect_plugin",
10+
srcs = ["wit_redirect_plugin.py"],
11+
srcs_version = "PY3",
12+
deps = [
13+
"//tensorboard/plugins:base_plugin",
14+
],
15+
)
16+
17+
py_test(
18+
name = "wit_redirect_plugin_test",
19+
srcs = ["wit_redirect_plugin_test.py"],
20+
srcs_version = "PY3",
21+
deps = [
22+
":wit_redirect_plugin",
23+
"//tensorboard:test",
24+
"//tensorboard/plugins:base_plugin",
25+
],
26+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
load("//tensorboard/defs:defs.bzl", "tf_ts_library")
2+
3+
package(default_visibility = ["//tensorboard:internal"])
4+
5+
licenses(["notice"])
6+
7+
tf_ts_library(
8+
name = "tf_wit_redirect_dashboard",
9+
srcs = ["tf-wit-redirect-dashboard.ts"],
10+
strict_checks = False,
11+
deps = [
12+
"//tensorboard/components/polymer:irons_and_papers",
13+
"//tensorboard/components/polymer:legacy_element_mixin",
14+
"@npm//@polymer/decorators",
15+
"@npm//@polymer/polymer",
16+
],
17+
)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
==============================================================================*/
15+
16+
import {customElement, property} from '@polymer/decorators';
17+
import {html, PolymerElement} from '@polymer/polymer';
18+
import '../../../components/polymer/irons_and_papers';
19+
import {LegacyElementMixin} from '../../../components/polymer/legacy_element_mixin';
20+
21+
/**
22+
* A frontend that directs users to install the Learning Interoperability Plugin
23+
* (LIT) instead of the What-If Tools, since the latter is no longer maintained.
24+
*/
25+
@customElement('tf-wit-redirect-dashboard')
26+
class TfWITRedirectDashboard extends LegacyElementMixin(PolymerElement) {
27+
static readonly template = html`
28+
<div class="message">
29+
<h3>The What-If Tool is no longer supported.</h3>
30+
<p>
31+
The
32+
<a href="https://pair-code.github.io/lit/"
33+
>Learning Interpretability Tool (LIT)</a
34+
>
35+
is an actively maintained alternative. Please follow the instructions
36+
<a href="https://pair-code.github.io/lit/setup/">here</a> to install and
37+
use this tool.
38+
</p>
39+
<style>
40+
:host {
41+
display: flex;
42+
}
43+
44+
.message {
45+
margin: 80px auto 0 auto;
46+
max-width: 540px;
47+
}
48+
#commandTextarea {
49+
margin-top: 1ex;
50+
padding: 1ex 1em;
51+
resize: vertical;
52+
width: 100%;
53+
}
54+
#copyContainer {
55+
display: flex;
56+
}
57+
#copiedMessage {
58+
align-self: center;
59+
flex-grow: 1;
60+
font-style: italic;
61+
padding-right: 1em;
62+
text-align: right;
63+
}
64+
</style>
65+
</div>
66+
`;
67+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Plugin that only displays a message with installation instructions."""
16+
17+
18+
from tensorboard.plugins import base_plugin
19+
20+
21+
class WITRedirectPluginLoader(base_plugin.TBLoader):
22+
"""Load the redirect notice iff the dynamic plugin is unavailable."""
23+
24+
def load(self, context):
25+
try:
26+
import tensorboard_plugin_wit # noqa: F401
27+
28+
# If we successfully load the dynamic plugin, don't show
29+
# this redirect plugin at all.
30+
return None
31+
except ImportError:
32+
return _WITRedirectPlugin(context)
33+
34+
35+
class _WITRedirectPlugin(base_plugin.TBPlugin):
36+
"""Redirect notice pointing users to the new dynamic LIT plugin."""
37+
38+
plugin_name = "wit_redirect"
39+
40+
def get_plugin_apps(self):
41+
return {}
42+
43+
def is_active(self):
44+
return False
45+
46+
def frontend_metadata(self):
47+
return base_plugin.FrontendMetadata(
48+
element_name="tf-wit-redirect-dashboard",
49+
tab_name="What-If Tool",
50+
)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
"""Tests for `wit_redirect_plugin`."""
16+
17+
18+
import contextlib
19+
import sys
20+
from unittest import mock
21+
22+
from tensorboard.plugins import base_plugin
23+
from tensorboard.plugins.wit_redirect import wit_redirect_plugin
24+
from tensorboard import test as tb_test
25+
26+
27+
_DYNAMIC_PLUGIN_MODULE = "tensorboard_plugin_wit"
28+
29+
30+
class WITRedirectPluginLoaderTest(tb_test.TestCase):
31+
"""Tests for `WITRedirectPluginLoader`."""
32+
33+
def test_loads_when_no_dynamic_plugin(self):
34+
with contextlib.ExitStack() as stack:
35+
stack.enter_context(mock.patch.dict(sys.modules))
36+
sys.modules.pop(_DYNAMIC_PLUGIN_MODULE, None)
37+
38+
real_import = __import__
39+
40+
def fake_import(name, *args, **kwargs):
41+
if name == _DYNAMIC_PLUGIN_MODULE:
42+
raise ImportError("Pretend I'm not here")
43+
else:
44+
return real_import(name, *args, **kwargs)
45+
46+
stack.enter_context(mock.patch("builtins.__import__", fake_import))
47+
48+
plugin_class = wit_redirect_plugin._WITRedirectPlugin
49+
plugin_init = stack.enter_context(
50+
mock.patch.object(plugin_class, "__init__", return_value=None)
51+
)
52+
53+
loader = wit_redirect_plugin.WITRedirectPluginLoader()
54+
context = base_plugin.TBContext()
55+
result = loader.load(context)
56+
self.assertIsInstance(result, plugin_class)
57+
plugin_init.assert_called_once_with(context)
58+
59+
def test_does_not_load_when_dynamic_plugin_present(self):
60+
with contextlib.ExitStack() as stack:
61+
stack.enter_context(mock.patch.dict(sys.modules))
62+
sys.modules.pop(_DYNAMIC_PLUGIN_MODULE, None)
63+
64+
real_import = __import__
65+
66+
def fake_import(name, *args, **kwargs):
67+
if name == _DYNAMIC_PLUGIN_MODULE:
68+
arbitrary_module = sys
69+
sys.modules.setdefault(
70+
_DYNAMIC_PLUGIN_MODULE, arbitrary_module
71+
)
72+
return arbitrary_module
73+
else:
74+
return real_import(name, *args, **kwargs)
75+
76+
stack.enter_context(mock.patch("builtins.__import__", fake_import))
77+
78+
plugin_class = wit_redirect_plugin._WITRedirectPlugin
79+
plugin_init = stack.enter_context(
80+
mock.patch.object(plugin_class, "__init__", return_value=None)
81+
)
82+
83+
loader = wit_redirect_plugin.WITRedirectPluginLoader()
84+
context = base_plugin.TBContext()
85+
result = loader.load(context)
86+
self.assertIsNone(result)
87+
plugin_init.assert_not_called()
88+
89+
90+
if __name__ == "__main__":
91+
tb_test.main()

tensorboard/tools/diagnose_tensorboard.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -254,23 +254,6 @@ def installed_packages():
254254
)
255255
yield Suggestion("Fix conflicting installations", message)
256256

257-
wit_version = packages.get("tensorboard-plugin-wit")
258-
if wit_version == "tensorboard-plugin-wit==1.6.0.post2":
259-
# This is only incompatible with TensorBoard prior to 2.2.0, but
260-
# we just issue a blanket warning so that we don't have to pull
261-
# in a `pkg_resources` dep to parse the version.
262-
preamble = reflow(
263-
"""
264-
Versions of the What-If Tool (`tensorboard-plugin-wit`)
265-
prior to 1.6.0.post3 are incompatible with some versions of
266-
TensorBoard. Please upgrade this package to the latest
267-
version to resolve any startup errors:
268-
"""
269-
)
270-
command = "pip install -U tensorboard-plugin-wit"
271-
message = "%s\n\n\t%s" % (preamble, command)
272-
yield Suggestion("Upgrade `tensorboard-plugin-wit`", message)
273-
274257

275258
@check
276259
def tensorboard_python_version():

0 commit comments

Comments
 (0)