{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Pruning Transformer with NNI\n\n## Workable Pruning Process\n\nHere we show an effective transformer pruning process that NNI team has tried, and users can use NNI to discover better processes.\n\nThe entire pruning process can be divided into the following steps:\n\n1. Finetune the pre-trained model on the downstream task. From our experience,\n   the final performance of pruning on the finetuned model is better than pruning directly on the pre-trained model.\n   At the same time, the finetuned model obtained in this step will also be used as the teacher model for the following\n   distillation training.\n2. Pruning the attention layer at first. Here we apply block-sparse on attention layer weight,\n   and directly prune the head (condense the weight) if the head was fully masked.\n   If the head was partially masked, we will not prune it and recover its weight.\n3. Retrain the head-pruned model with distillation. Recover the model precision before pruning FFN layer.\n4. Pruning the FFN layer. Here we apply the output channels pruning on the 1st FFN layer,\n   and the 2nd FFN layer input channels will be pruned due to the pruning of 1st layer output channels.\n5. Retrain the final pruned model with distillation.\n\nDuring the process of pruning transformer, we gained some of the following experiences:\n\n* We using `movement-pruner` in step 2 and `taylor-fo-weight-pruner` in step 4. `movement-pruner` has good performance on attention layers,\n  and `taylor-fo-weight-pruner` method has good performance on FFN layers. These two pruners are all some kinds of gradient-based pruning algorithms,\n  we also try weight-based pruning algorithms like `l1-norm-pruner`, but it doesn't seem to work well in this scenario.\n* Distillation is a good way to recover model precision. In terms of results, usually 1~2% improvement in accuracy can be achieved when we prune bert on mnli task.\n* It is necessary to gradually increase the sparsity rather than reaching a very high sparsity all at once.\n\n## Experiment\n\n### Preparation\nPlease set ``dev_mode`` to ``False`` to run this tutorial. Here ``dev_mode`` is ``True`` by default is for generating documents.\n\nThe complete pruning process takes about 8 hours on one A100.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "dev_mode = True"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Some basic setting.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from pathlib import Path\nfrom typing import Callable\n\npretrained_model_name_or_path = 'bert-base-uncased'\ntask_name = 'mnli'\nexperiment_id = 'pruning_bert'\n\n# heads_num and layers_num should align with pretrained_model_name_or_path\nheads_num = 12\nlayers_num = 12\n\n# used to save the experiment log\nlog_dir = Path(f'./pruning_log/{pretrained_model_name_or_path}/{task_name}/{experiment_id}')\nlog_dir.mkdir(parents=True, exist_ok=True)\n\n# used to save the finetuned model and share between different experiemnts with same pretrained_model_name_or_path and task_name\nmodel_dir = Path(f'./models/{pretrained_model_name_or_path}/{task_name}')\nmodel_dir.mkdir(parents=True, exist_ok=True)\n\nfrom transformers import set_seed\nset_seed(1024)\n\nimport torch\ndevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The function used to create dataloaders, note that 'mnli' has two evaluation dataset.\nIf teacher_model is set, will run all dataset on teacher model to get the 'teacher_logits' for distillation.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from torch.utils.data import DataLoader\n\nfrom datasets import load_dataset\nfrom transformers import BertTokenizerFast, DataCollatorWithPadding\n\ntask_to_keys = {\n    'cola': ('sentence', None),\n    'mnli': ('premise', 'hypothesis'),\n    'mrpc': ('sentence1', 'sentence2'),\n    'qnli': ('question', 'sentence'),\n    'qqp': ('question1', 'question2'),\n    'rte': ('sentence1', 'sentence2'),\n    'sst2': ('sentence', None),\n    'stsb': ('sentence1', 'sentence2'),\n    'wnli': ('sentence1', 'sentence2'),\n}\n\ndef prepare_data(cache_dir='./data', train_batch_size=32, eval_batch_size=32,\n                    teacher_model: torch.nn.Module = None):\n    tokenizer = BertTokenizerFast.from_pretrained(pretrained_model_name_or_path)\n    sentence1_key, sentence2_key = task_to_keys[task_name]\n    data_collator = DataCollatorWithPadding(tokenizer)\n\n    # used to preprocess the raw data\n    def preprocess_function(examples):\n        # Tokenize the texts\n        args = (\n            (examples[sentence1_key],) if sentence2_key is None else (examples[sentence1_key], examples[sentence2_key])\n        )\n        result = tokenizer(*args, padding=False, max_length=128, truncation=True)\n\n        if 'label' in examples:\n            # In all cases, rename the column to labels because the model will expect that.\n            result['labels'] = examples['label']\n        return result\n\n    raw_datasets = load_dataset('glue', task_name, cache_dir=cache_dir)\n    for key in list(raw_datasets.keys()):\n        if 'test' in key:\n            raw_datasets.pop(key)\n\n    processed_datasets = raw_datasets.map(preprocess_function, batched=True,\n                                            remove_columns=raw_datasets['train'].column_names)\n\n    # if has teacher model, add 'teacher_logits' to datasets who has 'labels'.\n    # 'teacher_logits' is used for distillation and avoid the double counting.\n    if teacher_model:\n        teacher_model_training = teacher_model.training\n        teacher_model.eval()\n        model_device = next(teacher_model.parameters()).device\n\n        def add_teacher_logits(examples):\n            result = {k: v for k, v in examples.items()}\n            samples = data_collator(result).to(model_device)\n            if 'labels' in samples:\n                with torch.no_grad():\n                    logits = teacher_model(**samples).logits.tolist()\n                result['teacher_logits'] = logits\n            return result\n\n        processed_datasets = processed_datasets.map(add_teacher_logits, batched=True,\n                                                    batch_size=train_batch_size)\n        teacher_model.train(teacher_model_training)\n\n    train_dataset = processed_datasets['train']\n    validation_dataset = processed_datasets['validation_matched' if task_name == 'mnli' else 'validation']\n    validation_dataset2 = processed_datasets['validation_mismatched'] if task_name == 'mnli' else None\n\n    train_dataloader = DataLoader(train_dataset,\n                                    shuffle=True,\n                                    collate_fn=data_collator,\n                                    batch_size=train_batch_size)\n    validation_dataloader = DataLoader(validation_dataset,\n                                        collate_fn=data_collator,\n                                        batch_size=eval_batch_size)\n    validation_dataloader2 = DataLoader(validation_dataset2,\n                                        collate_fn=data_collator,\n                                        batch_size=eval_batch_size) if task_name == 'mnli' else None\n\n    return train_dataloader, validation_dataloader, validation_dataloader2"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Training function & evaluation function.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import time\nimport torch.nn.functional as F\nfrom datasets import load_metric\n\ndef training(train_dataloader: DataLoader,\n                model: torch.nn.Module,\n                optimizer: torch.optim.Optimizer,\n                criterion: Callable[[torch.Tensor, torch.Tensor], torch.Tensor],\n                lr_scheduler: torch.optim.lr_scheduler._LRScheduler = None,\n                max_steps: int = None, max_epochs: int = None,\n                save_best_model: bool = False, save_path: str = None,\n                log_path: str = Path(log_dir) / 'training.log',\n                distillation: bool = False,\n                evaluation_func=None):\n    model.train()\n    current_step = 0\n    best_result = 0\n\n    for current_epoch in range(max_epochs if max_epochs else 1):\n        for batch in train_dataloader:\n            batch.to(device)\n            teacher_logits = batch.pop('teacher_logits', None)\n            optimizer.zero_grad()\n            outputs = model(**batch)\n            loss = outputs.loss\n\n            if distillation:\n                assert teacher_logits is not None\n                distil_loss = F.kl_div(F.log_softmax(outputs.logits / 2, dim=-1),\n                                        F.softmax(teacher_logits / 2, dim=-1), reduction='batchmean') * (2 ** 2)\n                loss = 0.1 * loss + 0.9 * distil_loss\n\n            loss = criterion(loss, None)\n            loss.backward()\n            optimizer.step()\n\n            if lr_scheduler:\n                lr_scheduler.step()\n\n            current_step += 1\n\n            # evaluation for every 1000 steps\n            if current_step % 1000 == 0 or current_step % len(train_dataloader) == 0:\n                result = evaluation_func(model) if evaluation_func else None\n                with (log_path).open('a+') as f:\n                    msg = '[{}] Epoch {}, Step {}: {}\\n'.format(time.asctime(time.localtime(time.time())), current_epoch, current_step, result)\n                    f.write(msg)\n                # if it's the best model, save it.\n                if save_best_model and best_result < result['default']:\n                    assert save_path is not None\n                    torch.save(model.state_dict(), save_path)\n                    best_result = result['default']\n\n            if max_steps and current_step >= max_steps:\n                return\n\ndef evaluation(validation_dataloader: DataLoader,\n                validation_dataloader2: DataLoader,\n                model: torch.nn.Module):\n    training = model.training\n    model.eval()\n    is_regression = task_name == 'stsb'\n    metric = load_metric('glue', task_name)\n\n    for batch in validation_dataloader:\n        batch.pop('teacher_logits', None)\n        batch.to(device)\n        outputs = model(**batch)\n        predictions = outputs.logits.argmax(dim=-1) if not is_regression else outputs.logits.squeeze()\n        metric.add_batch(\n            predictions=predictions,\n            references=batch['labels'],\n        )\n    result = metric.compute()\n\n    if validation_dataloader2:\n        for batch in validation_dataloader2:\n            batch.pop('teacher_logits', None)\n            batch.to(device)\n            outputs = model(**batch)\n            predictions = outputs.logits.argmax(dim=-1) if not is_regression else outputs.logits.squeeze()\n            metric.add_batch(\n                predictions=predictions,\n                references=batch['labels'],\n            )\n        result = {'matched': result, 'mismatched': metric.compute()}\n        result['default'] = (result['matched']['accuracy'] + result['mismatched']['accuracy']) / 2\n    else:\n        result['default'] = result.get('f1', result.get('accuracy', None))\n\n    model.train(training)\n    return result\n\n# using huggingface native loss\ndef fake_criterion(outputs, targets):\n    return outputs"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Prepare pre-trained model and finetuning on downstream task.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import functools\n\nfrom torch.optim import Adam\nfrom torch.optim.lr_scheduler import LambdaLR\nfrom transformers import BertForSequenceClassification\n\ndef create_pretrained_model():\n    is_regression = task_name == 'stsb'\n    num_labels = 1 if is_regression else (3 if task_name == 'mnli' else 2)\n    return BertForSequenceClassification.from_pretrained(pretrained_model_name_or_path, num_labels=num_labels)\n\ndef create_finetuned_model():\n    pretrained_model = create_pretrained_model().to(device)\n\n    train_dataloader, validation_dataloader, validation_dataloader2 = prepare_data()\n    evaluation_func = functools.partial(evaluation, validation_dataloader, validation_dataloader2)\n    steps_per_epoch = len(train_dataloader)\n    training_epochs = 3\n\n    finetuned_model_state_path = Path(model_dir) / 'finetuned_model_state.pth'\n\n    if finetuned_model_state_path.exists():\n        pretrained_model.load_state_dict(torch.load(finetuned_model_state_path))\n    elif dev_mode:\n        pass\n    else:\n        optimizer = Adam(pretrained_model.parameters(), lr=3e-5, eps=1e-8)\n\n        def lr_lambda(current_step: int):\n            return max(0.0, float(training_epochs * steps_per_epoch - current_step) / float(training_epochs * steps_per_epoch))\n\n        lr_scheduler = LambdaLR(optimizer, lr_lambda)\n        training(train_dataloader, pretrained_model, optimizer, fake_criterion, lr_scheduler=lr_scheduler, max_epochs=training_epochs,\n                    save_best_model=True, save_path=finetuned_model_state_path, evaluation_func=evaluation_func)\n    return pretrained_model\n\nfinetuned_model = create_finetuned_model()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Using finetuned model as teacher model to create dataloader.\nAdd 'teacher_logits' to dataset, it is used to do the distillation, it can be seen as a kind of data label.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "if not dev_mode:\n    train_dataloader, validation_dataloader, validation_dataloader2 = prepare_data(teacher_model=finetuned_model)\nelse:\n    train_dataloader, validation_dataloader, validation_dataloader2 = prepare_data()\n\nevaluation_func = functools.partial(evaluation, validation_dataloader, validation_dataloader2)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### Pruning\nFirst, using MovementPruner to prune attention head.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "steps_per_epoch = len(train_dataloader)\n\n# Set training steps/epochs for pruning.\n\nif not dev_mode:\n    total_epochs = 4\n    total_steps = total_epochs * steps_per_epoch\n    warmup_steps = 1 * steps_per_epoch\n    cooldown_steps = 1 * steps_per_epoch\nelse:\n    total_epochs = 1\n    total_steps = 3\n    warmup_steps = 1\n    cooldown_steps = 1\n\n# Initialize evaluator used by MovementPruner.\n\nimport nni\nfrom nni.algorithms.compression.v2.pytorch import TorchEvaluator\n\nmovement_training = functools.partial(training, train_dataloader, log_path=log_dir / 'movement_pruning.log',\n                                    evaluation_func=evaluation_func)\ntraced_optimizer = nni.trace(Adam)(finetuned_model.parameters(), lr=3e-5, eps=1e-8)\n\ndef lr_lambda(current_step: int):\n    if current_step < warmup_steps:\n        return float(current_step) / warmup_steps\n    return max(0.0, float(total_steps - current_step) / float(total_steps - warmup_steps))\n\ntraced_scheduler = nni.trace(LambdaLR)(traced_optimizer, lr_lambda)\nevaluator = TorchEvaluator(movement_training, traced_optimizer, fake_criterion, traced_scheduler)\n\n# Apply block-soft-movement pruning on attention layers.\n\nfrom nni.compression.pytorch.pruning import MovementPruner\n\nconfig_list = [{'op_types': ['Linear'], 'op_partial_names': ['bert.encoder.layer.{}.'.format(i) for i in range(layers_num)], 'sparsity': 0.1}]\npruner = MovementPruner(model=finetuned_model,\n                        config_list=config_list,\n                        evaluator=evaluator,\n                        training_epochs=total_epochs,\n                        training_steps=total_steps,\n                        warm_up_step=warmup_steps,\n                        cool_down_beginning_step=total_steps - cooldown_steps,\n                        regular_scale=10,\n                        movement_mode='soft',\n                        sparse_granularity='auto')\n_, attention_masks = pruner.compress()\npruner.show_pruned_weights()\n\ntorch.save(attention_masks, Path(log_dir) / 'attention_masks.pth')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Load a new finetuned model to do the speedup.\nNote that nni speedup don't support replace attention module, so here we manully replace the attention module.\n\nIf the head is entire masked, physically prune it and create config_list for FFN pruning.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "attention_pruned_model = create_finetuned_model().to(device)\nattention_masks = torch.load(Path(log_dir) / 'attention_masks.pth')\n\nffn_config_list = []\nlayer_count = 0\nmodule_list = []\nfor i in range(0, layers_num):\n    prefix = f'bert.encoder.layer.{i}.'\n    value_mask: torch.Tensor = attention_masks[prefix + 'attention.self.value']['weight']\n    head_mask = (value_mask.reshape(heads_num, -1).sum(-1) == 0.)\n    head_idx = torch.arange(len(head_mask))[head_mask].long().tolist()\n    print(f'layer {i} pruner {len(head_idx)} head: {head_idx}')\n    if len(head_idx) != heads_num:\n        attention_pruned_model.bert.encoder.layer[i].attention.prune_heads(head_idx)\n        module_list.append(attention_pruned_model.bert.encoder.layer[i])\n        # The final ffn weight remaining ratio is the half of the attention weight remaining ratio.\n        # This is just an empirical configuration, you can use any other method to determine this sparsity.\n        sparsity = 1 - (1 - len(head_idx) / heads_num) * 0.5\n        # here we use a simple sparsity schedule, we will prune ffn in 12 iterations, each iteration prune `sparsity_per_iter`.\n        sparsity_per_iter = 1 - (1 - sparsity) ** (1 / heads_num)\n        ffn_config_list.append({'op_names': [f'bert.encoder.layer.{layer_count}.intermediate.dense'], 'sparsity': sparsity_per_iter})\n        layer_count += 1\n\nattention_pruned_model.bert.encoder.layer = torch.nn.ModuleList(module_list)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Retrain the attention pruned model with distillation.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "if not dev_mode:\n    total_epochs = 5\n    total_steps = None\n    distillation = True\nelse:\n    total_epochs = 1\n    total_steps = 1\n    distillation = False\n\noptimizer = Adam(attention_pruned_model.parameters(), lr=3e-5, eps=1e-8)\n\ndef lr_lambda(current_step: int):\n    return max(0.0, float(total_epochs * steps_per_epoch - current_step) / float(total_epochs * steps_per_epoch))\n\nlr_scheduler = LambdaLR(optimizer, lr_lambda)\nat_model_save_path = log_dir / 'attention_pruned_model_state.pth'\ntraining(train_dataloader, attention_pruned_model, optimizer, fake_criterion, lr_scheduler=lr_scheduler,\n         max_epochs=total_epochs, max_steps=total_steps, save_best_model=True, save_path=at_model_save_path,\n         distillation=distillation, evaluation_func=evaluation_func)\n\nif not dev_mode:\n    attention_pruned_model.load_state_dict(torch.load(at_model_save_path))"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Iterative pruning FFN with TaylorFOWeightPruner in 12 iterations.\nFinetuning 2000 steps after each iteration, then finetuning 2 epochs after pruning finished.\n\nNNI will support per-step-pruning-schedule in the future, then can use an pruner to replace the following code.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "if not dev_mode:\n    total_epochs = 4\n    total_steps = None\n    taylor_pruner_steps = 1000\n    steps_per_iteration = 2000\n    total_pruning_steps = 24000\n    distillation = True\nelse:\n    total_epochs = 1\n    total_steps = 6\n    taylor_pruner_steps = 2\n    steps_per_iteration = 2\n    total_pruning_steps = 4\n    distillation = False\n\nfrom nni.compression.pytorch.pruning import TaylorFOWeightPruner\nfrom nni.compression.pytorch.speedup import ModelSpeedup\n\ndistil_training = functools.partial(training, train_dataloader, log_path=log_dir / 'taylor_pruning.log',\n                                    distillation=distillation, evaluation_func=evaluation_func)\ntraced_optimizer = nni.trace(Adam)(attention_pruned_model.parameters(), lr=3e-5, eps=1e-8)\nevaluator = TorchEvaluator(distil_training, traced_optimizer, fake_criterion)\n\ncurrent_step = 0\nbest_result = 0\ninit_lr = 3e-5\n\ndummy_input = torch.rand(8, 128, 768).to(device)\n\nattention_pruned_model.train()\nfor current_epoch in range(total_epochs):\n    for batch in train_dataloader:\n        if total_steps and current_step >= total_steps:\n            break\n        # pruning 12 times\n        if current_step % steps_per_iteration == 0 and current_step < total_pruning_steps:\n            check_point = attention_pruned_model.state_dict()\n            pruner = TaylorFOWeightPruner(attention_pruned_model, ffn_config_list, evaluator, taylor_pruner_steps)\n            _, ffn_masks = pruner.compress()\n            renamed_ffn_masks = {}\n            # rename the masks keys, because we only speedup the bert.encoder\n            for model_name, targets_mask in ffn_masks.items():\n                renamed_ffn_masks[model_name.split('bert.encoder.')[1]] = targets_mask\n            pruner._unwrap_model()\n            attention_pruned_model.load_state_dict(check_point)\n            ModelSpeedup(attention_pruned_model.bert.encoder, dummy_input, renamed_ffn_masks).speedup_model()\n            optimizer = Adam(attention_pruned_model.parameters(), lr=init_lr)\n\n        batch.to(device)\n        teacher_logits = batch.pop('teacher_logits', None)\n        optimizer.zero_grad()\n\n        # manually schedule lr\n        for params_group in optimizer.param_groups:\n            params_group['lr'] = (1 - current_step / (total_epochs * steps_per_epoch)) * init_lr\n\n        outputs = attention_pruned_model(**batch)\n        loss = outputs.loss\n\n        # distillation\n        if teacher_logits is not None:\n            distil_loss = F.kl_div(F.log_softmax(outputs.logits / 2, dim=-1),\n                                    F.softmax(teacher_logits / 2, dim=-1), reduction='batchmean') * (2 ** 2)\n            loss = 0.1 * loss + 0.9 * distil_loss\n        loss.backward()\n        optimizer.step()\n\n        current_step += 1\n        if current_step % 1000 == 0 or current_step % len(train_dataloader) == 0:\n            result = evaluation_func(attention_pruned_model)\n            with (log_dir / 'ffn_pruning.log').open('a+') as f:\n                msg = '[{}] Epoch {}, Step {}: {}\\n'.format(time.asctime(time.localtime(time.time())),\n                                                            current_epoch, current_step, result)\n                f.write(msg)\n            if current_step >= total_pruning_steps and best_result < result['default']:\n                torch.save(attention_pruned_model, log_dir / 'best_model.pth')\n                best_result = result['default']"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Result\nThe speedup is test on the entire validation dataset with batch size 32 on A100.\nWe test under two pytorch version and found the latency varying widely.\n\nSetting 1: pytorch 1.12.1\n\nSetting 2: pytorch 1.10.0\n\n.. list-table:: Prune Bert-base-uncased on MNLI\n    :header-rows: 1\n    :widths: auto\n\n    * - Attention Pruning Method\n      - FFN Pruning Method\n      - Total Sparsity\n      - Accuracy\n      - Acc. Drop\n      - Speedup (S1)\n      - Speedup (S2)\n    * -\n      -\n      - 0%\n      - 84.73 / 84.63\n      - +0.0 / +0.0\n      - 12.56s (x1.00)\n      - 4.05s (x1.00)\n    * - `movement-pruner` (soft, th=0.1, lambda=5)\n      - `taylor-fo-weight-pruner`\n      - 51.39%\n      - 84.25 / 84.96\n      - -0.48 / +0.33\n      - 6.85s (x1.83)\n      - 2.7s (x1.50)\n    * - `movement-pruner` (soft, th=0.1, lambda=10)\n      - `taylor-fo-weight-pruner`\n      - 66.67%\n      - 83.98 / 83.75\n      - -0.75 / -0.88\n      - 4.73s (x2.66)\n      - 2.16s (x1.86)\n    * - `movement-pruner` (soft, th=0.1, lambda=20)\n      - `taylor-fo-weight-pruner`\n      - 77.78%\n      - 83.02 / 83.06\n      - -1.71 / -1.57\n      - 3.35s (x3.75)\n      - 1.72s (x2.35)\n    * - `movement-pruner` (soft, th=0.1, lambda=30)\n      - `taylor-fo-weight-pruner`\n      - 87.04%\n      - 81.24 / 80.99\n      - -3.49 / -3.64\n      - 2.19s (x5.74)\n      - 1.31s (x3.09)\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.13"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}