Skip to content

diff

allennlp.commands.diff

[SOURCE]


Examples

allennlp diff \
    hf://roberta-large/pytorch_model.bin \
    https://storage.googleapis.com/allennlp-public-models/transformer-qa-2020-10-03.tar.gz \
    --strip-prefix-1 'roberta.' \
    --strip-prefix-2 '_text_field_embedder.token_embedder_tokens.transformer_model.'

Diff

@Subcommand.register("diff")
class Diff(Subcommand)

requires_plugins

class Diff(Subcommand):
 | ...
 | requires_plugins: bool = False

add_subparser

class Diff(Subcommand):
 | ...
 | def add_subparser(
 |     self,
 |     parser: argparse._SubParsersAction
 | ) -> argparse.ArgumentParser

Keep

class Keep(NamedTuple)

key

class Keep(NamedTuple):
 | ...
 | key: str = None

shape

class Keep(NamedTuple):
 | ...
 | shape: Tuple[int, ...] = None

display

class Keep(NamedTuple):
 | ...
 | def display(self)

Insert

class Insert(NamedTuple)

key

class Insert(NamedTuple):
 | ...
 | key: str = None

shape

class Insert(NamedTuple):
 | ...
 | shape: Tuple[int, ...] = None

display

class Insert(NamedTuple):
 | ...
 | def display(self)

Remove

class Remove(NamedTuple)

key

class Remove(NamedTuple):
 | ...
 | key: str = None

shape

class Remove(NamedTuple):
 | ...
 | shape: Tuple[int, ...] = None

display

class Remove(NamedTuple):
 | ...
 | def display(self)

Modify

class Modify(NamedTuple)

key

class Modify(NamedTuple):
 | ...
 | key: str = None

shape

class Modify(NamedTuple):
 | ...
 | shape: Tuple[int, ...] = None

distance

class Modify(NamedTuple):
 | ...
 | distance: float = None

display

class Modify(NamedTuple):
 | ...
 | def display(self)

checkpoint_diff

def checkpoint_diff(
    state_dict_a: Dict[str, torch.Tensor],
    state_dict_b: Dict[str, torch.Tensor],
    scale: float,
    threshold: float
) -> List[Union[Keep, Insert, Remove, Modify]]

Uses a modified version of the Myers diff algorithm to compute a representation of the diff between two model state dictionaries.

The only difference is that in addition to the Keep, Insert, and Remove operations, we add Modify. This corresponds to keeping a parameter but changing its weights (not the shape).

Adapted from this gist.