Skip to content

plot_topk_overlap

Plot top-k neuron overlap between models.

Uses a Venn diagram for 2-6 models and a heatmap for larger model sets.

Parameters:

Name Type Description Default
models Union[Dict[str, object], List[object]]

Mapping of display/model ids to GRADIEND models, or a list of models, e.g. [trainer.get_model() for trainer in trainers]. Models in a list are labelled after their checkpoint folders (runs/3SG_3PL/model -> "3SG_3PL"); if no unique label can be derived, pass a dict instead.

required
topk int

Number or fraction of top weights to compare.

100
part str

Model part used to select weights.

'decoder-weight'
output_path Optional[str]

Optional output path.

None
show bool

Whether to display the plot.

False
**kwargs Any

Forwarded to the selected Venn or heatmap implementation.

{}
Source code in gradiend/visualizer/topk/__init__.py
def plot_topk_overlap(
    models: Union[Dict[str, object], List[object]],
    topk: int = 100,
    part: str = "decoder-weight",
    output_path: Optional[str] = None,
    show: bool = False,
    **kwargs: Any,
):
    """Plot top-k neuron overlap between models.

    Uses a Venn diagram for 2-6 models and a heatmap for larger model sets.

    Args:
        models: Mapping of display/model ids to GRADIEND models, or a list of models, e.g.
            ``[trainer.get_model() for trainer in trainers]``. Models in a list are labelled after
            their checkpoint folders (``runs/3SG_3PL/model`` -> ``"3SG_3PL"``); if no unique label can
            be derived, pass a dict instead.
        topk: Number or fraction of top weights to compare.
        part: Model part used to select weights.
        output_path: Optional output path.
        show: Whether to display the plot.
        **kwargs: Forwarded to the selected Venn or heatmap implementation.
    """
    models = as_named_models(models)
    if len(models) <= 6:
        venn_kw = {
            k: v
            for k, v in kwargs.items()
            if k
            in (
                "figsize",
                "circle_names_fontsize",
                "region_counts_fontsize",
                "patch_linewidth",
                "alpha",
                "title",
                "highlight_non_convergence",
            )
        }
        return plot_topk_overlap_venn(models, topk=topk, part=part, output_path=output_path, show=show, **venn_kw)
    return plot_topk_overlap_heatmap(models, topk=topk, part=part, output_path=output_path, show=show, **kwargs)