Repository: facebookresearch/xformers

Issue:
ViT example broke with the model_factory refactor
# 🐛 Bug
Breaks on the config, we should add a quick run on that one also to make sure that this does not happen

## Command
`python3 xformers/benchmarks/benchmark_vit_timm.py`

Callstack
```
Global seed set to 42
Traceback (most recent call last):
  File "/home/lefaudeux/Git/xformers/xformers/benchmarks/benchmark_vit_timm.py", line 364, in <module>
    lm = VisionTransformer(
  File "/home/lefaudeux/Git/xformers/xformers/benchmarks/benchmark_vit_timm.py", line 188, in __init__
    config = xFormerConfig(xformer_config)
  File "/home/lefaudeux/Git/xformers/xformers/factory/model_factory.py", line 40, in __init__
    if config["block_type"] == "encoder":
KeyError: 'block_type'
```



Discussion:

Resolving patch:
diff --git a/xformers/benchmarks/benchmark_vit_timm.py b/xformers/benchmarks/benchmark_vit_timm.py
--- a/xformers/benchmarks/benchmark_vit_timm.py
+++ b/xformers/benchmarks/benchmark_vit_timm.py
@@ -147,7 +147,6 @@ def __init__(
                 num_heads=n_head,
                 mlp_ratio=hidden_layer_multiplier,
                 qkv_bias=True,
-                distilled=False,
                 drop_rate=resid_pdrop,
                 attn_drop_rate=attn_pdrop,
                 drop_path_rate=0,
@@ -160,28 +159,26 @@ def __init__(
             # A list of the encoder or decoder blocks which constitute the Transformer.
             xformer_config = [
                 {
-                    "block_config": {
-                        "block_type": "encoder",
-                        "num_layers": n_layer,
-                        "dim_model": dim,
-                        "seq_len": num_patches,
-                        "layer_norm_style": "pre",
-                        "multi_head_config": {
-                            "num_heads": n_head,
-                            "residual_dropout": resid_pdrop,
-                            "attention": {
-                                "name": attention,
-                                "dropout": attn_pdrop,
-                                "causal": False,
-                            },
+                    "block_type": "encoder",
+                    "num_layers": n_layer,
+                    "dim_model": dim,
+                    "layer_norm_style": "pre",
+                    "multi_head_config": {
+                        "num_heads": n_head,
+                        "residual_dropout": resid_pdrop,
+                        "attention": {
+                            "name": attention,
+                            "dropout": attn_pdrop,
+                            "causal": False,
+                            "seq_len": num_patches,
                         },
-                        "feedforward_config": {
-                            "name": "FusedMLP",
-                            "dropout": mlp_pdrop,
-                            "activation": "gelu",
-                            "hidden_layer_multiplier": hidden_layer_multiplier,
-                        },
-                    }
+                    },
+                    "feedforward_config": {
+                        "name": "FusedMLP",
+                        "dropout": mlp_pdrop,
+                        "activation": "gelu",
+                        "hidden_layer_multiplier": hidden_layer_multiplier,
+                    },
                 }
             ]
 
@@ -336,6 +333,14 @@ def test_step(self, batch, batch_idx):
         default=False,
     )
 
+    parser.add_argument(
+        "-samples",
+        "--samples",
+        help="Number of random samples to generate",
+        type=int,
+        default=128,
+    )
+
     args = parser.parse_args()
 
     pl.seed_everything(42)
@@ -344,7 +349,7 @@ def test_step(self, batch, batch_idx):
     NUM_WORKERS = 4
     GPUS = 1
     IMG_SIZE = 224
-    NUM_SAMPLES = 128
+    NUM_SAMPLES = args.samples
     NUM_CLASSES = 10
     N_LAYERS = 4
 


Test patch: