File size: 1,622 Bytes
377e8b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Configuration for NoTokenLM-ImageGen-Class-2.5 (hybrid conv/attention ImageNet-1k classifier)."""
from transformers import PretrainedConfig


class NTLMClass25Config(PretrainedConfig):
    """Architecture hyper-parameters. Field names mirror the JAX training code (`ntlm_core.Cfg`)."""

    model_type = "ntlm_class25"

    def __init__(
        self,
        widths=(64, 128, 256, 384),   # channels of the 4 stages
        depths=(2, 3, 3, 2),          # blocks per stage (stage 1 = Fused-MBConv, stages 2-4 = ConvNeXt-style)
        ratios=(4, 4, 4, 3),          # MLP / expansion ratio per stage
        heads=4,                      # attention heads (global attention, last block of stage 4)
        head_dim=1024,                # width of the hidden layer of the classification head
        num_classes=1000,
        dw_k=7,                       # depthwise kernel size of the ConvNeXt blocks
        ls_init=1e-2,                 # layer-scale init (irrelevant at inference)
        drop_path=0.1,                # stochastic depth rate (training only, unused here)
        default_resolution=128,       # resolution the final training stages used
        **kwargs,
    ):
        self.widths = list(widths)
        self.depths = list(depths)
        self.ratios = list(ratios)
        self.heads = heads
        self.head_dim = head_dim
        self.num_classes = num_classes
        self.dw_k = dw_k
        self.ls_init = ls_init
        self.drop_path = drop_path
        self.default_resolution = default_resolution
        kwargs.setdefault("num_labels", num_classes)
        super().__init__(**kwargs)