(
bdf_rel_long: pd.DataFrame,
show_providers: list[str],
use_errorbar: bool = False,
)
| 183 | |
| 184 | |
| 185 | def plot_relative_performance( |
| 186 | bdf_rel_long: pd.DataFrame, |
| 187 | show_providers: list[str], |
| 188 | use_errorbar: bool = False, |
| 189 | ) -> None: |
| 190 | plot_df = bdf_rel_long.query("provider in @show_providers") |
| 191 | palette = _provider_palette(show_providers) |
| 192 | _, ax = plt.subplots(figsize=(10, 6)) |
| 193 | barplot_kwargs = {} |
| 194 | if use_errorbar: |
| 195 | barplot_kwargs["errorbar"] = minmax_skip_zero_range |
| 196 | barplot_kwargs["err_kws"] = {"linewidth": 2.5, "color": "black"} |
| 197 | sns.barplot( |
| 198 | plot_df, |
| 199 | x="n_hidden_states", |
| 200 | y="relative-perf", |
| 201 | hue="provider", |
| 202 | hue_order=show_providers, |
| 203 | palette=palette, |
| 204 | ax=ax, |
| 205 | **barplot_kwargs, |
| 206 | ) |
| 207 | hatches = [PROVIDER_HATCHES.get(p, "") for p in show_providers] |
| 208 | bar_containers = [ |
| 209 | c for c in ax.containers if isinstance(c, plt.matplotlib.container.BarContainer) |
| 210 | ] |
| 211 | for container, hatch in zip(bar_containers, hatches): |
| 212 | for bar in container: |
| 213 | bar.set_hatch(hatch) |
| 214 | ax.grid(alpha=0.5, axis="y") |
| 215 | fontsize = 18 |
| 216 | sns.move_legend( |
| 217 | ax, |
| 218 | "upper center", |
| 219 | title="Method", |
| 220 | bbox_to_anchor=(0.5, 1.3), |
| 221 | ncol=len(show_providers), |
| 222 | fontsize=fontsize, |
| 223 | title_fontsize=fontsize, |
| 224 | ) |
| 225 | for handle, hatch in zip(ax.get_legend().legend_handles, hatches): |
| 226 | handle.set_hatch(hatch) |
| 227 | ax.set_xlabel("Batch Size", fontsize=fontsize) |
| 228 | ax.set_ylabel("Relative Performance", fontsize=fontsize) |
| 229 | ax.set_xticks(ax.get_xticks(), labels=bdf_rel_long["n_hidden_states"].unique().astype(int)) |
| 230 | ax.yaxis.set_major_locator(plt.MultipleLocator(0.25)) |
| 231 | ax.tick_params(axis="both", labelsize=fontsize) |
| 232 | ax.figure.tight_layout() |
| 233 | return ax |
| 234 | |
| 235 | |
| 236 | def model_bytes(vocab_size: int, hidden_size: int, n_hidden_states: float) -> float: |
no test coverage detected