Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion devtools/inspector/_inspector_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def style_text_size(val, size=12):
return f"font-size: {size}px"

if get_ipython() is not None:
styled_df = df.style.applymap(style_text_size)
styled_df = df.style.map(style_text_size)
display(styled_df)
else:
raise Exception(
Expand Down
28 changes: 28 additions & 0 deletions devtools/inspector/tests/inspector_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@

# pyre-unsafe

import io
import math
import os
import sys
import tempfile
import types
import unittest
import warnings
from typing import Dict, Tuple
from unittest.mock import patch

import executorch.exir.tests.models as models
import pandas as pd

import torch
from executorch.devtools import generate_etrecord, parse_etrecord
Expand All @@ -35,6 +41,7 @@
compare_results,
convert_to_float_tensor,
create_debug_handle_to_op_node_mapping,
display_or_print_df,
EDGE_DIALECT_GRAPH_KEY,
find_op_names,
find_populated_event,
Expand Down Expand Up @@ -279,6 +286,27 @@ def test_plot_metric_empty_result(self):
self.assertEqual(os.listdir(tmp_dir), [])
self.assertEqual(plt.get_fignums(), [])

def test_display_or_print_df_in_ipython(self):
displayed = []
fake_display = types.ModuleType("IPython.display")
fake_display.display = displayed.append
fake_ipython = types.ModuleType("IPython")
fake_ipython.get_ipython = lambda: object()
fake_ipython.display = fake_display
out = io.StringIO()
with patch.dict(
sys.modules, {"IPython": fake_ipython, "IPython.display": fake_display}
), warnings.catch_warnings():
# Styler.applymap is deprecated in pandas 2.1 and removed in 3.0.
warnings.filterwarnings(
"error", message=".*applymap.*", category=FutureWarning
)
display_or_print_df(pd.DataFrame({"a": [1.0]}), out)
self.assertEqual(len(displayed), 1, out.getvalue())
self.assertIsInstance(displayed[0], pd.io.formats.style.Styler)
self.assertIn("font-size: 12px", displayed[0].to_html())
self.assertEqual(out.getvalue(), "")

def test_merge_overlapping_debug_handles_basic(self):
big_tensor = torch.rand(100, 100)
intermediate_outputs = {
Expand Down
Loading