Download experiments/latency-degradation/paper/plot.py from MLL-Lab/LAGEN-datasets: direct link, hf CLI and curl.
- Browser
- Download file 7.63 kB
-
https://huggingface.co/datasets/MLL-Lab/LAGEN-datasets/resolve/main/experiments/latency-degradation/paper/plot.py
- Command line
-
hf download hf://datasets/MLL-Lab/LAGEN-datasets/experiments/latency-degradation/paper/plot.py
-
curl -L -o plot.py https://huggingface.co/datasets/MLL-Lab/LAGEN-datasets/resolve/main/experiments/latency-degradation/paper/plot.py
7.63 kB
| from __future__ import annotations | |
| import csv | |
| import math | |
| from pathlib import Path | |
| import matplotlib | |
| import sys | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[2])) | |
| import paper_colors | |
| matplotlib.use("Agg") | |
| import matplotlib.pyplot as plt | |
| from matplotlib.lines import Line2D | |
| plt.rcParams.update(paper_colors.RC_COLORS) | |
| HERE = Path(__file__).resolve().parent | |
| DATA_CSV = HERE / "data.csv" | |
| MODEL_LABELS = { | |
| "OpenVLA": "OpenVLA*", | |
| "pi_0.5": r"$\pi_{0.5}$*", | |
| "GR00T": "GR00T*", | |
| } | |
| MODELS = ["OpenVLA", "pi_0.5", "GR00T"] | |
| MARKERS = { | |
| "OpenVLA": "o", | |
| "pi_0.5": "s", | |
| "GR00T": "^", | |
| } | |
| MIKASA_MODELS = ["qwenoft", "qwenpi_v3", "qwengr00t"] | |
| MIKASA_COLORS = { | |
| "qwenoft": paper_colors.MODEL_COLORS["Qwen OFT"], | |
| "qwenpi_v3": paper_colors.MODEL_COLORS["QwenPI"], | |
| "qwengr00t": paper_colors.MODEL_COLORS["QwenGR00T"], | |
| } | |
| MIKASA_MARKERS = {"qwenoft": "o", "qwenpi_v3": "s", "qwengr00t": "^"} | |
| PANEL_CONFIGS = [ | |
| { | |
| "env": "Flappy Bird", | |
| "latencies": [0, 1, 2, 3, 4], | |
| "ylim": (0, 500), | |
| "inset_latencies": [1, 2, 3, 4], | |
| "inset_ylim": (0, 22), | |
| "inset_xticks": [1, 2, 3, 4], | |
| "inset_yticks": [0, 10, 20], | |
| }, | |
| { | |
| "env": "Demon Attack", | |
| "latencies": [0, 2, 4], | |
| "ylim": (0, 7000), | |
| "inset_latencies": [2, 4], | |
| "inset_ylim": (50, 320), | |
| "inset_xticks": [2, 4], | |
| "inset_yticks": [100, 200, 300], | |
| }, | |
| { | |
| "env": "Deadly Corridor", | |
| "latencies": [0, 1, 2, 3, 4, 5], | |
| "ylim": (0, 700), | |
| "inset_latencies": [1, 2, 3, 4, 5], | |
| "inset_ylim": (50, 280), | |
| "inset_xticks": [1, 3, 5], | |
| "inset_yticks": [80, 160, 240], | |
| }, | |
| ] | |
| def load_data() -> dict[str, dict[str, dict[int, float]]]: | |
| data: dict[str, dict[str, dict[int, float]]] = {} | |
| with DATA_CSV.open("r", newline="", encoding="utf-8") as handle: | |
| for row in csv.DictReader(handle): | |
| env = row["env"] | |
| model = row["model"] | |
| horizon = row["horizon"] | |
| latency = int(row["latency"]) | |
| mean_score = float(row["mean_score"]) | |
| series = model if not horizon else f"{model}_{horizon.lower()}" | |
| data.setdefault(env, {}).setdefault(series, {})[latency] = mean_score | |
| return data | |
| def plot_lines(ax, curves: dict[str, dict[int, float]], latencies: list[int], *, small: bool) -> None: | |
| for model in MODELS: | |
| values = curves[model] | |
| ys = [values[latency] for latency in latencies] | |
| ax.plot( | |
| latencies, | |
| ys, | |
| marker=MARKERS[model], | |
| color=paper_colors.MODEL_COLORS[model], | |
| ls="-", | |
| lw=0.8 if small else 1.2, | |
| ms=2.2 if small else 3.2, | |
| alpha=0.98, | |
| zorder=4 if model == "OpenVLA" else 3, | |
| ) | |
| def plot_env(ax, config: dict[str, object], data: dict[str, dict[str, dict[int, float]]]) -> None: | |
| env = config["env"] | |
| curves = data[env] | |
| latencies = config["latencies"] | |
| inset_latencies = config["inset_latencies"] | |
| plot_lines(ax, curves, latencies, small=False) | |
| ax.set_title(env, pad=7) | |
| ax.set_xlabel("Eval latency (frames)") | |
| ax.set_xticks(latencies) | |
| ax.set_xlim(min(latencies) - 0.25, max(latencies) + 0.25) | |
| ax.set_ylim(*config["ylim"]) | |
| if env == "Flappy Bird": | |
| ax.set_yticks([0, 100, 200, 300, 400, 500]) | |
| axins = ax.inset_axes([0.52, 0.53, 0.44, 0.35]) | |
| axins.set_facecolor(paper_colors.WHITE) | |
| axins.patch.set_alpha(0.94) | |
| plot_lines(axins, curves, inset_latencies, small=True) | |
| axins.set_xlim(min(inset_latencies) - 0.2, max(inset_latencies) + 0.2) | |
| axins.set_ylim(*config["inset_ylim"]) | |
| axins.set_xticks(config["inset_xticks"]) | |
| axins.set_yticks(config["inset_yticks"]) | |
| axins.tick_params(labelsize=5.5, length=2) | |
| axins.grid(alpha=0.25) | |
| axins.set_title("Zoom: latency > 0", fontsize=5.5, pad=2) | |
| for spine in axins.spines.values(): | |
| spine.set_color(paper_colors.GRAY) | |
| spine.set_linewidth(0.5) | |
| # Derive the source box from the inset limits so both views stay aligned. | |
| zoom = ax.indicate_inset_zoom( | |
| axins, | |
| edgecolor=paper_colors.EDGE, | |
| linewidth=0.65, | |
| linestyle="--", | |
| alpha=0.8, | |
| zorder=2, | |
| ) | |
| for connector in zoom.connectors: | |
| connector.set_visible(False) | |
| # A single arrow avoids the inset's y ticks and enters between x ticks. | |
| inset_left, inset_right = axins.get_xlim() | |
| ax.annotate( | |
| "", | |
| xy=(0.25, 0), | |
| xycoords=axins.transAxes, | |
| xytext=((inset_left + inset_right) / 2, axins.get_ylim()[1]), | |
| textcoords=ax.transData, | |
| arrowprops={ | |
| "arrowstyle": "->", | |
| "color": paper_colors.EDGE, | |
| "linewidth": 0.65, | |
| "linestyle": "--", | |
| "alpha": 0.8, | |
| "mutation_scale": 7, | |
| "shrinkA": 1.5, | |
| "shrinkB": 1.5, | |
| }, | |
| zorder=2, | |
| ) | |
| def plot_mikasa(ax, data: dict[str, dict[str, dict[int, float]]]) -> None: | |
| curves = data["MIKASA InterceptGrabFast"] | |
| latencies = [0, 1, 2, 3, 4] | |
| max_success = max( | |
| value | |
| for values in curves.values() | |
| for value in values.values() | |
| ) | |
| y_max = math.ceil(max_success / 10) * 10 | |
| for model in MIKASA_MODELS: | |
| for horizon in (1, 8): | |
| values = curves[f"{model}_h{horizon}"] | |
| ax.plot( | |
| latencies, | |
| [values[latency] for latency in latencies], | |
| marker=MIKASA_MARKERS[model], | |
| color=MIKASA_COLORS[model], | |
| ls="-" if horizon == 1 else "--", | |
| lw=1.15, | |
| ms=3.0, | |
| markerfacecolor=MIKASA_COLORS[model] if horizon == 1 else paper_colors.WHITE, | |
| markeredgewidth=0.8, | |
| ) | |
| ax.set_title("Intercept Grab (Fast)", pad=7) | |
| ax.set_xlabel("Eval latency (frames)") | |
| ax.set_ylabel("Success rate (%)", labelpad=1) | |
| ax.set_xticks(latencies) | |
| ax.set_xlim(-0.25, 4.25) | |
| ax.set_ylim(0, y_max) | |
| ax.set_yticks(range(0, y_max + 1, 10)) | |
| def main() -> None: | |
| plt.style.use(HERE.parents[1] / "plot_style.mplstyle") | |
| data = load_data() | |
| fig, axes = plt.subplots(1, 4, figsize=(7.2, 2.45), constrained_layout=False) | |
| for ax, config in zip(axes[:3], PANEL_CONFIGS): | |
| plot_env(ax, config, data) | |
| plot_mikasa(axes[3], data) | |
| for ax in axes: | |
| ax.set_box_aspect(1) | |
| handles = [ | |
| Line2D([], [], color=paper_colors.MODEL_COLORS[model], | |
| marker=MARKERS[model], linestyle="None", markersize=5, | |
| label=MODEL_LABELS[model]) | |
| for model in MODELS | |
| ] | |
| handles.extend(( | |
| Line2D([], [], color=paper_colors.INK, marker="o", markersize=4, | |
| label="Single action"), | |
| Line2D([], [], color=paper_colors.INK, linestyle="--", marker="o", | |
| markerfacecolor=paper_colors.WHITE, markersize=4, | |
| label="Action chunk (horizon 8)"), | |
| )) | |
| fig.legend(handles=handles, loc="upper center", ncol=5, | |
| bbox_to_anchor=(0.5, 0.95), fontsize=7, frameon=False, | |
| handlelength=1.4, handletextpad=0.35, columnspacing=0.8) | |
| axes[0].set_ylabel("Mean return") | |
| fig.subplots_adjust(left=0.055, right=0.995, bottom=0.22, top=0.76, wspace=0.38) | |
| fig.savefig(HERE / "fig.pdf", bbox_inches="tight") | |
| fig.savefig(HERE / "fig.png", dpi=300, bbox_inches="tight") | |
| plt.close(fig) | |
| print(f"wrote {HERE / 'fig.pdf'}") | |
| print(f"wrote {HERE / 'fig.png'}") | |
| if __name__ == "__main__": | |
| main() | |