MCPcopy
hub / github.com/QData/TextAttack / from_checkpoint

Method from_checkpoint

textattack/attacker.py:465–487  ·  view source on GitHub ↗

Resume attacking from a saved checkpoint. Attacker and dataset must be recovered by the user again, while attack args are loaded from the saved checkpoint. Args: attack (:class:`~textattack.Attack`): Attack object for carrying out the attack.

(cls, attack, dataset, checkpoint)

Source from the content-addressed store, hash-verified

463
464 @classmethod
465 def from_checkpoint(cls, attack, dataset, checkpoint):
466 """Resume attacking from a saved checkpoint. Attacker and dataset must
467 be recovered by the user again, while attack args are loaded from the
468 saved checkpoint.
469
470 Args:
471 attack (:class:`~textattack.Attack`):
472 Attack object for carrying out the attack.
473 dataset (:class:`~textattack.datasets.Dataset`):
474 Dataset to attack.
475 checkpoint (:obj:`Union[str, :class:`~textattack.shared.AttackChecpoint`]`):
476 Path of saved checkpoint or the actual saved checkpoint.
477 """
478 assert isinstance(
479 checkpoint, (str, textattack.shared.AttackCheckpoint)
480 ), f"`checkpoint` must be of type `str` or `textattack.shared.AttackCheckpoint`, but got type `{type(checkpoint)}`."
481
482 if isinstance(checkpoint, str):
483 checkpoint = textattack.shared.AttackCheckpoint.load(checkpoint)
484 attacker = cls(attack, dataset, checkpoint.attack_args)
485 attacker.attack_log_manager = checkpoint.attack_log_manager
486 attacker._checkpoint = checkpoint
487 return attacker
488
489 @staticmethod
490 def attack_interactive(attack):

Callers 1

runMethod · 0.80

Calls 1

loadMethod · 0.80

Tested by

no test coverage detected