def create_model(
        model_name: str = None,
        context_length: int = 77,
        pretrained: bool = False,
        weights_path: str = None,
        device: Union[str, torch.device] = None,
) -> CLIP4Clip:
    """
    Create a CLIP4Clip model.
    Args:
        model_name (`str`):
            Model name, `clip_vit_b16` or `clip_vit_b32`.
        context_length (`int`):
            Length of context sequence, default is 77, the same as these in CLIP.
        pretrained (`bool`):
            Whether pretained model.
        weights_path (`str`):
            Your local trained weights path. default is None.
        device (`str`):
            Model device, `cpu` or `cuda`.

    Returns:
        (`CLIP4Clip`):
            CLIP4Clip model.
    >>> from towhee.models import clip4clip
    >>> model = clip4clip.create_model(model_name="clip_vit_b32", context_length=32, pretrained=False, device='cpu')
    >>> model.__class__.__name__
    'CLIP4Clip'

    """
    configs = get_configs(model_name)
    if "multilingual_model" in configs:
        configs.pop("multilingual_model")
    if "url" in configs:
        configs.pop("url")
    configs["context_length"] = context_length
    model = CLIP4Clip(**configs)
    model.to(device)
    if pretrained and weights_path is not None:
        state_dict = torch.load(weights_path, map_location=device)
        missing_keys = []
        unexpected_keys = []
        error_msgs = []
        metadata = getattr(state_dict, "_metadata", None)
        state_dict = state_dict.copy()
        if metadata is not None:
            state_dict._metadata = metadata  # pylint: disable=protected-access

        def load(module, prefix=""):
            local_metadata = {} if metadata is None else metadata.get(prefix[:-1], {})
            module._load_from_state_dict(   # pylint: disable=protected-access
                state_dict, prefix, local_metadata, True, missing_keys, unexpected_keys, error_msgs)
            for name, child in module._modules.items():   # pylint: disable=protected-access
                if child is not None:
                    load(child, prefix + name + ".")

        load(model, prefix="")

        if len(missing_keys) > 0:
            logger.info("Weights of %s not initialized from pretrained model: %s", model.__class__.__name__,
                        "\n   " + "\n   ".join(missing_keys))
        if len(unexpected_keys) > 0:
            logger.info("Weights from pretrained model not used in %s: %s", model.__class__.__name__,
                        "\n   " + "\n   ".join(unexpected_keys))
        if len(error_msgs) > 0:
            logger.error("Weights from pretrained model cause errors in %s: %s", model.__class__.__name__,
                         "\n   " + "\n   ".join(error_msgs))

    if pretrained and weights_path is None:
        raise ValueError("weights_path is None")
    return model
Create a CLIP4Clip model.
Args:
model_name (`str`):
Model name, `clip_vit_b16` or `clip_vit_b32`.
context_length (`int`):
Length of context sequence, default is 77, the same as these in CLIP.
pretrained (`bool`):
Whether pretained model.
weights_path (`str`):
Your local trained weights path. default is None.
device (`str`):
Model device, `cpu` or `cuda`.

Returns:
(`CLIP4Clip`):
CLIP4Clip model.
>>> from towhee.models import clip4clip
>>> model = clip4clip.create_model(model_name="clip_vit_b32", context_length=32, pretrained=False, device='cpu')
>>> model.__class__.__name__
'CLIP4Clip'
towhee/models/clip4clip/clip4clip.py