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 bit model configuration from configurationutils import pretrainedconfig from utils import logging from utils backboneutils import backboneconfigmixin getalignedoutputfeaturesoutputindices logger logging getloggername bitpretrainedconfigarchivemap googlebit50 https huggingface cogooglebit50resolvemainconfig json class bitconfigbackboneconfigmixin pretrainedconfig r this is the configuration class to store the configuration of a bitmodel it is used to instantiate an bit 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 bit googlebit50https huggingface cogooglebit50 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 embeddingsize int optional defaults to 64 dimensionality hidden size for the embedding layer hiddensizes listint optional defaults to 256 512 1024 2048 dimensionality hidden size at each stage depths listint optional defaults to 3 4 6 3 depth number of layers for each stage layertype str optional defaults to preactivation the layer to use it can be either preactivation or bottleneck hiddenact str optional defaults to relu the nonlinear activation function in each block if string gelu relu selu and gelunew are supported globalpadding str optional padding strategy to use for the convolutional layers can be either valid same or none numgroups int optional defaults to 32 number of groups used for the bitgroupnormactivation layers droppathrate float optional defaults to 0 0 the drop path rate for the stochastic depth embeddingdynamicpadding bool optional defaults to false whether or not to make use of dynamic padding for the embedding layer outputstride int optional defaults to 32 the output stride of the model widthfactor int optional defaults to 1 the width factor for the model outfeatures liststr optional if used as backbone list of features to output can be any of stem stage1 stage2 etc depending on how many stages the model has if unset and outindices is set will default to the corresponding stages if unset and outindices is unset will default to the last stage outindices listint optional if used as backbone list of indices of features to output can be any of 0 1 2 etc depending on how many stages the model has if unset and outfeatures is set will default to the corresponding stages if unset and outfeatures is unset will default to the last stage example python from transformers import bitconfig bitmodel initializing a bit bit50 style configuration configuration bitconfig initializing a model with random weights from the bit50 style configuration model bitmodelconfiguration accessing the model configuration configuration model config 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 bit model configuration this is the configuration class to store the configuration of a bitmodel it is used to instantiate an bit 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 bit google bit 50 https huggingface co google bit 50 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 embedding_size int optional defaults to 64 dimensionality hidden size for the embedding layer hidden_sizes list int optional defaults to 256 512 1024 2048 dimensionality hidden size at each stage depths list int optional defaults to 3 4 6 3 depth number of layers for each stage layer_type str optional defaults to preactivation the layer to use it can be either preactivation or bottleneck hidden_act str optional defaults to relu the non linear activation function in each block if string gelu relu selu and gelu_new are supported global_padding str optional padding strategy to use for the convolutional layers can be either valid same or none num_groups int optional defaults to 32 number of groups used for the bitgroupnormactivation layers drop_path_rate float optional defaults to 0 0 the drop path rate for the stochastic depth embedding_dynamic_padding bool optional defaults to false whether or not to make use of dynamic padding for the embedding layer output_stride int optional defaults to 32 the output stride of the model width_factor int optional defaults to 1 the width factor for the model out_features list str optional if used as backbone list of features to output can be any of stem stage1 stage2 etc depending on how many stages the model has if unset and out_indices is set will default to the corresponding stages if unset and out_indices is unset will default to the last stage out_indices list int optional if used as backbone list of indices of features to output can be any of 0 1 2 etc depending on how many stages the model has if unset and out_features is set will default to the corresponding stages if unset and out_features is unset will default to the last stage example python from transformers import bitconfig bitmodel initializing a bit bit 50 style configuration configuration bitconfig initializing a model with random weights from the bit 50 style configuration model bitmodel configuration accessing the model configuration configuration model config
from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


logger = logging.get_logger(__name__)

BIT_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "google/bit-50": "https://huggingface.co/google/bit-50/resolve/main/config.json",
}


class BitConfig(BackboneConfigMixin, PretrainedConfig):
    r

    model_type = "bit"
    layer_types = ["preactivation", "bottleneck"]
    supported_padding = ["SAME", "VALID"]

    def __init__(
        self,
        num_channels=3,
        embedding_size=64,
        hidden_sizes=[256, 512, 1024, 2048],
        depths=[3, 4, 6, 3],
        layer_type="preactivation",
        hidden_act="relu",
        global_padding=None,
        num_groups=32,
        drop_path_rate=0.0,
        embedding_dynamic_padding=False,
        output_stride=32,
        width_factor=1,
        out_features=None,
        out_indices=None,
        **kwargs,
    ):
        super().__init__(**kwargs)
        if layer_type not in self.layer_types:
            raise ValueError(f"layer_type={layer_type} is not one of {','.join(self.layer_types)}")
        if global_padding is not None:
            if global_padding.upper() in self.supported_padding:
                global_padding = global_padding.upper()
            else:
                raise ValueError(f"Padding strategy {global_padding} not supported")
        self.num_channels = num_channels
        self.embedding_size = embedding_size
        self.hidden_sizes = hidden_sizes
        self.depths = depths
        self.layer_type = layer_type
        self.hidden_act = hidden_act
        self.global_padding = global_padding
        self.num_groups = num_groups
        self.drop_path_rate = drop_path_rate
        self.embedding_dynamic_padding = embedding_dynamic_padding
        self.output_stride = output_stride
        self.width_factor = width_factor

        self.stage_names = ["stem"] + [f"stage{idx}" for idx in range(1, len(depths) + 1)]
        self._out_features, self._out_indices = get_aligned_output_features_output_indices(
            out_features=out_features, out_indices=out_indices, stage_names=self.stage_names
        )