codingutf8 2022 sea ai labs and 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 poolformer model configuration from collections import ordereddict from typing import mapping from packaging import version from configurationutils import pretrainedconfig from onnx import onnxconfig from utils import logging logger logging getloggername poolformerpretrainedconfigarchivemap sailpoolformers12 https huggingface cosailpoolformers12resolvemainconfig json see all poolformer models at https huggingface comodels filterpoolformer class poolformerconfigpretrainedconfig r this is the configuration class to store the configuration of poolformermodel it is used to instantiate a poolformer 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 poolformer sailpoolformers12https huggingface cosailpoolformers12 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 channels in the input image patchsize int optional defaults to 16 the size of the input patch stride int optional defaults to 16 the stride of the input patch poolsize int optional defaults to 3 the size of the pooling window mlpratio float optional defaults to 4 0 the ratio of the number of channels in the output of the mlp to the number of channels in the input depths list optional defaults to 2 2 6 2 the depth of each encoder block hiddensizes list optional defaults to 64 128 320 512 the hidden sizes of each encoder block patchsizes list optional defaults to 7 3 3 3 the size of the input patch for each encoder block strides list optional defaults to 4 2 2 2 the stride of the input patch for each encoder block padding list optional defaults to 2 1 1 1 the padding of the input patch for each encoder block numencoderblocks int optional defaults to 4 the number of encoder blocks droppathrate float optional defaults to 0 0 the dropout rate for the dropout layers hiddenact str optional defaults to gelu the activation function for the hidden layers uselayerscale bool optional defaults to true whether to use layer scale layerscaleinitvalue float optional defaults to 1e05 the initial value for the layer scale initializerrange float optional defaults to 0 02 the initializer range for the weights example python from transformers import poolformerconfig poolformermodel initializing a poolformer sailpoolformers12 style configuration configuration poolformerconfig initializing a model with random weights from the sailpoolformers12 style configuration model poolformermodelconfiguration accessing the model configuration configuration model config coding utf 8 2022 sea ai labs and 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 poolformer model configuration see all poolformer models at https huggingface co models filter poolformer this is the configuration class to store the configuration of poolformermodel it is used to instantiate a poolformer 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 poolformer sail poolformer_s12 https huggingface co sail poolformer_s12 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 channels in the input image patch_size int optional defaults to 16 the size of the input patch stride int optional defaults to 16 the stride of the input patch pool_size int optional defaults to 3 the size of the pooling window mlp_ratio float optional defaults to 4 0 the ratio of the number of channels in the output of the mlp to the number of channels in the input depths list optional defaults to 2 2 6 2 the depth of each encoder block hidden_sizes list optional defaults to 64 128 320 512 the hidden sizes of each encoder block patch_sizes list optional defaults to 7 3 3 3 the size of the input patch for each encoder block strides list optional defaults to 4 2 2 2 the stride of the input patch for each encoder block padding list optional defaults to 2 1 1 1 the padding of the input patch for each encoder block num_encoder_blocks int optional defaults to 4 the number of encoder blocks drop_path_rate float optional defaults to 0 0 the dropout rate for the dropout layers hidden_act str optional defaults to gelu the activation function for the hidden layers use_layer_scale bool optional defaults to true whether to use layer scale layer_scale_init_value float optional defaults to 1e 05 the initial value for the layer scale initializer_range float optional defaults to 0 02 the initializer range for the weights example python from transformers import poolformerconfig poolformermodel initializing a poolformer sail poolformer_s12 style configuration configuration poolformerconfig initializing a model with random weights from the sail poolformer_s12 style configuration model poolformermodel configuration accessing the model configuration configuration model config
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


logger = logging.get_logger(__name__)

POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP = {
    "sail/poolformer_s12": "https://huggingface.co/sail/poolformer_s12/resolve/main/config.json",
    
}


class PoolFormerConfig(PretrainedConfig):
    r

    model_type = "poolformer"

    def __init__(
        self,
        num_channels=3,
        patch_size=16,
        stride=16,
        pool_size=3,
        mlp_ratio=4.0,
        depths=[2, 2, 6, 2],
        hidden_sizes=[64, 128, 320, 512],
        patch_sizes=[7, 3, 3, 3],
        strides=[4, 2, 2, 2],
        padding=[2, 1, 1, 1],
        num_encoder_blocks=4,
        drop_path_rate=0.0,
        hidden_act="gelu",
        use_layer_scale=True,
        layer_scale_init_value=1e-5,
        initializer_range=0.02,
        **kwargs,
    ):
        self.num_channels = num_channels
        self.patch_size = patch_size
        self.stride = stride
        self.padding = padding
        self.pool_size = pool_size
        self.hidden_sizes = hidden_sizes
        self.mlp_ratio = mlp_ratio
        self.depths = depths
        self.patch_sizes = patch_sizes
        self.strides = strides
        self.num_encoder_blocks = num_encoder_blocks
        self.drop_path_rate = drop_path_rate
        self.hidden_act = hidden_act
        self.use_layer_scale = use_layer_scale
        self.layer_scale_init_value = layer_scale_init_value
        self.initializer_range = initializer_range
        super().__init__(**kwargs)


class PoolFormerOnnxConfig(OnnxConfig):
    torch_onnx_minimum_version = version.parse("1.11")

    @property
    def inputs(self) -> Mapping[str, Mapping[int, str]]:
        return OrderedDict(
            [
                ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
            ]
        )

    @property
    def atol_for_validation(self) -> float:
        return 2e-3