MCPcopy Create free account
hub / github.com/OpenPipe/ART / plot_packed_tensors

Function plot_packed_tensors

src/art/preprocessing/pack.py:262–306  ·  view source on GitHub ↗
(
    packed_tensors: PackedTensors, output_dir: str | None = None
)

Source from the content-addressed store, hash-verified

260
261
262def plot_packed_tensors(
263 packed_tensors: PackedTensors, output_dir: str | None = None
264) -> None:
265 try:
266 import matplotlib.pyplot as plt
267 import seaborn as sns
268 except ImportError:
269 raise ImportError(
270 "Plotting dependencies are not installed. Please install them with: "
271 "pip install openpipe-art[plotting]"
272 )
273
274 plt.figure(figsize=(15, 24))
275
276 for tensor, label, title, subplot_idx in (
277 (packed_tensors["tokens"], "Token IDs", "Token IDs", 1),
278 (packed_tensors["logprobs"], "Log Probabilities", "Token Log Probs", 2),
279 (packed_tensors["group_ids"], "Group IDs", "Token Groups", 3),
280 (packed_tensors["parent_ids"], "Parent IDs", "Parent IDs", 4),
281 (packed_tensors["input_pos"], "Position", "Input Position", 5),
282 (packed_tensors["assistant_mask"], "Assistant Mask", "Assistant Mask", 6),
283 (packed_tensors["advantages"], "Advantages", "Token Advantages", 7),
284 (packed_tensors["weights"], "Weights", "Token Weights", 8),
285 ):
286 plt.subplot(4, 2, subplot_idx)
287 sns.heatmap(
288 tensor.numpy(),
289 cmap="viridis",
290 cbar_kws={"label": label},
291 xticklabels=False,
292 )
293 plt.title(title)
294 plt.xlabel("Sequence Position")
295 plt.ylabel("Batch")
296
297 plt.tight_layout()
298 plt.show()
299
300 if output_dir:
301 os.makedirs(output_dir, exist_ok=True)
302 plot_path = f"{output_dir}/packed_tensors_plot_{int(time.time())}.png"
303 plt.savefig(plot_path)
304 print(f"Plot saved to: {plot_path}")
305 else:
306 print("No output directory specified, plot not saved")

Callers 1

_get_packed_tensorsMethod · 0.85

Calls 1

timeMethod · 0.80

Tested by

no test coverage detected