def create_model(
        model_name: str = None,
        pretrained: bool = False,
        weights_path: str = None,
        device: str = None,
        **kwargs
):
    """
    Create BridgeFormer model.

    Args:
        model_name (`str`):
            - "clip_initialized_model": use the clip_vit_b32 model.
            - "bridge_former_training": use the bridge former training model Architecture.
            - Others: use the default inference bridge former model Architecture.
        pretrained (`bool`):
            Flag to control if load pretrained model.
        weights_path (`str`):
            The path of local model weights.
        device (`str`):
            Device, defaults to None. If None, use cuda when it is available.
    """
    if device is None:
        device = "cuda" if torch.cuda.is_available() else "cpu"
    if pretrained and weights_path is None:
        raise AssertionError("if pretrained is true, weights_path needs to be specified")

    if model_name == "clip_initialized_model":
        model = clip.create_model(model_name="clip_vit_b32", pretrained=False,
                                  is_bridge_former=True, is_bridge_former_video=True, **kwargs)
        if pretrained:
            checkpoint = torch.load(weights_path, map_location=device)
            state_dict = checkpoint["state_dict"]
            state_dict = state_dict_data_parallel_fix(state_dict, model.state_dict())
            for key in ["input_resolution", "context_length", "vocab_size"]:
                if key in state_dict:
                    del state_dict[key]
            if device != "cpu":
                # CPU training, does not support half-precision numbers
                convert_weights(model)
            model.load_state_dict(state_dict, strict=True)

    elif model_name == "bridge_former_training":
        model = BridgeFormerTraining(weights_path=weights_path,
                                     is_pretrained=pretrained,
                                     device=device,
                                     **kwargs)

    else:
        model = FrozenInTime(weights_path=weights_path,
                             is_pretrained=pretrained,
                             attention_style="bridge_former",
                             device=device,
                             **kwargs)

    model.eval()
    model.to(device)
    return model
Create BridgeFormer model.

Args:
model_name (`str`):
- "clip_initialized_model": use the clip_vit_b32 model.
- "bridge_former_training": use the bridge former training model Architecture.
- Others: use the default inference bridge former model Architecture.
pretrained (`bool`):
Flag to control if load pretrained model.
weights_path (`str`):
The path of local model weights.
device (`str`):
Device, defaults to None. If None, use cuda when it is available.
towhee/models/bridgeformer/bridge_former.py