codingutf8 2022 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license cvt model configuration from configurationutils import pretrainedconfig from utils import logging logger logging getloggername cvtpretrainedconfigarchivemap microsoftcvt13 https huggingface comicrosoftcvt13resolvemainconfig json see all cvt models at https huggingface comodels filtercvt class cvtconfigpretrainedconfig r this is the configuration class to store the configuration of a cvtmodel it is used to instantiate a cvt model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the cvt microsoftcvt13https huggingface comicrosoftcvt13 architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args numchannels int optional defaults to 3 the number of input channels patchsizes listint optional defaults to 7 3 3 the kernel size of each encoder s patch embedding patchstride listint optional defaults to 4 2 2 the stride size of each encoder s patch embedding patchpadding listint optional defaults to 2 1 1 the padding size of each encoder s patch embedding embeddim listint optional defaults to 64 192 384 dimension of each of the encoder blocks numheads listint optional defaults to 1 3 6 number of attention heads for each attention layer in each block of the transformer encoder depth listint optional defaults to 1 2 10 the number of layers in each encoder block mlpratios listfloat optional defaults to 4 0 4 0 4 0 4 0 ratio of the size of the hidden layer compared to the size of the input layer of the mix ffns in the encoder blocks attentiondroprate listfloat optional defaults to 0 0 0 0 0 0 the dropout ratio for the attention probabilities droprate listfloat optional defaults to 0 0 0 0 0 0 the dropout ratio for the patch embeddings probabilities droppathrate listfloat optional defaults to 0 0 0 0 0 1 the dropout probability for stochastic depth used in the blocks of the transformer encoder qkvbias listbool optional defaults to true true true the bias bool for query key and value in attentions clstoken listbool optional defaults to false false true whether or not to add a classification token to the output of each of the last 3 stages qkvprojectionmethod liststring optional defaults to dwbn dwbn dwbn the projection method for query key and value default is depthwise convolutions with batch norm for linear projection use avg kernelqkv listint optional defaults to 3 3 3 the kernel size for query key and value in attention layer paddingkv listint optional defaults to 1 1 1 the padding size for key and value in attention layer stridekv listint optional defaults to 2 2 2 the stride size for key and value in attention layer paddingq listint optional defaults to 1 1 1 the padding size for query in attention layer strideq listint optional defaults to 1 1 1 the stride size for query in attention layer initializerrange float optional defaults to 0 02 the standard deviation of the truncatednormalinitializer for initializing all weight matrices layernormeps float optional defaults to 1e6 the epsilon used by the layer normalization layers example python from transformers import cvtconfig cvtmodel initializing a cvt msftcvt style configuration configuration cvtconfig initializing a model with random weights from the msftcvt style configuration model cvtmodelconfiguration accessing the model configuration configuration model config modeltype cvt def init self numchannels3 patchsizes7 3 3 patchstride4 2 2 patchpadding2 1 1 embeddim64 192 384 numheads1 3 6 depth1 2 10 mlpratio4 0 4 0 4 0 attentiondroprate0 0 0 0 0 0 droprate0 0 0 0 0 0 droppathrate0 0 0 0 0 1 qkvbiastrue true true clstokenfalse false true qkvprojectionmethoddwbn dwbn dwbn kernelqkv3 3 3 paddingkv1 1 1 stridekv2 2 2 paddingq1 1 1 strideq1 1 1 initializerrange0 02 layernormeps1e12 kwargs super initkwargs self numchannels numchannels self patchsizes patchsizes self patchstride patchstride self patchpadding patchpadding self embeddim embeddim self numheads numheads self depth depth self mlpratio mlpratio self attentiondroprate attentiondroprate self droprate droprate self droppathrate droppathrate self qkvbias qkvbias self clstoken clstoken self qkvprojectionmethod qkvprojectionmethod self kernelqkv kernelqkv self paddingkv paddingkv self stridekv stridekv self paddingq paddingq self strideq strideq self initializerrange initializerrange self layernormeps layernormeps coding utf 8 2022 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license cvt model configuration see all cvt models at https huggingface co models filter cvt this is the configuration class to store the configuration of a cvtmodel it is used to instantiate a cvt model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the cvt microsoft cvt 13 https huggingface co microsoft cvt 13 architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args num_channels int optional defaults to 3 the number of input channels patch_sizes list int optional defaults to 7 3 3 the kernel size of each encoder s patch embedding patch_stride list int optional defaults to 4 2 2 the stride size of each encoder s patch embedding patch_padding list int optional defaults to 2 1 1 the padding size of each encoder s patch embedding embed_dim list int optional defaults to 64 192 384 dimension of each of the encoder blocks num_heads list int optional defaults to 1 3 6 number of attention heads for each attention layer in each block of the transformer encoder depth list int optional defaults to 1 2 10 the number of layers in each encoder block mlp_ratios list float optional defaults to 4 0 4 0 4 0 4 0 ratio of the size of the hidden layer compared to the size of the input layer of the mix ffns in the encoder blocks attention_drop_rate list float optional defaults to 0 0 0 0 0 0 the dropout ratio for the attention probabilities drop_rate list float optional defaults to 0 0 0 0 0 0 the dropout ratio for the patch embeddings probabilities drop_path_rate list float optional defaults to 0 0 0 0 0 1 the dropout probability for stochastic depth used in the blocks of the transformer encoder qkv_bias list bool optional defaults to true true true the bias bool for query key and value in attentions cls_token list bool optional defaults to false false true whether or not to add a classification token to the output of each of the last 3 stages qkv_projection_method list string optional defaults to dw_bn dw_bn dw_bn the projection method for query key and value default is depth wise convolutions with batch norm for linear projection use avg kernel_qkv list int optional defaults to 3 3 3 the kernel size for query key and value in attention layer padding_kv list int optional defaults to 1 1 1 the padding size for key and value in attention layer stride_kv list int optional defaults to 2 2 2 the stride size for key and value in attention layer padding_q list int optional defaults to 1 1 1 the padding size for query in attention layer stride_q list int optional defaults to 1 1 1 the stride size for query in attention layer initializer_range float optional defaults to 0 02 the standard deviation of the truncated_normal_initializer for initializing all weight matrices layer_norm_eps float optional defaults to 1e 6 the epsilon used by the layer normalization layers example python from transformers import cvtconfig cvtmodel initializing a cvt msft cvt style configuration configuration cvtconfig initializing a model with random weights from the msft cvt style configuration model cvtmodel configuration accessing the model configuration configuration model config
from ...configuration_utils import PretrainedConfig
from ...utils import logging


logger = logging.get_logger(__name__)

CVT_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "microsoft/cvt-13": "https://huggingface.co/microsoft/cvt-13/resolve/main/config.json",
    
}


class CvtConfig(PretrainedConfig):
    r

    model_type = "cvt"

    def __init__(
        self,
        num_channels=3,
        patch_sizes=[7, 3, 3],
        patch_stride=[4, 2, 2],
        patch_padding=[2, 1, 1],
        embed_dim=[64, 192, 384],
        num_heads=[1, 3, 6],
        depth=[1, 2, 10],
        mlp_ratio=[4.0, 4.0, 4.0],
        attention_drop_rate=[0.0, 0.0, 0.0],
        drop_rate=[0.0, 0.0, 0.0],
        drop_path_rate=[0.0, 0.0, 0.1],
        qkv_bias=[True, True, True],
        cls_token=[False, False, True],
        qkv_projection_method=["dw_bn", "dw_bn", "dw_bn"],
        kernel_qkv=[3, 3, 3],
        padding_kv=[1, 1, 1],
        stride_kv=[2, 2, 2],
        padding_q=[1, 1, 1],
        stride_q=[1, 1, 1],
        initializer_range=0.02,
        layer_norm_eps=1e-12,
        **kwargs,
    ):
        super().__init__(**kwargs)
        self.num_channels = num_channels
        self.patch_sizes = patch_sizes
        self.patch_stride = patch_stride
        self.patch_padding = patch_padding
        self.embed_dim = embed_dim
        self.num_heads = num_heads
        self.depth = depth
        self.mlp_ratio = mlp_ratio
        self.attention_drop_rate = attention_drop_rate
        self.drop_rate = drop_rate
        self.drop_path_rate = drop_path_rate
        self.qkv_bias = qkv_bias
        self.cls_token = cls_token
        self.qkv_projection_method = qkv_projection_method
        self.kernel_qkv = kernel_qkv
        self.padding_kv = padding_kv
        self.stride_kv = stride_kv
        self.padding_q = padding_q
        self.stride_q = stride_q
        self.initializer_range = initializer_range
        self.layer_norm_eps = layer_norm_eps