Spaces:
Running
Running
File size: 3,543 Bytes
891e05c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | # Copyright (c) Meta Platforms, Inc. and affiliates.
"""
Include all available vision encoder configurations.
"""
from dataclasses import dataclass, replace
from functools import partial
from typing import Callable, Optional, Sequence, Tuple, List
from huggingface_hub import hf_hub_download
def fetch_pe_checkpoint(name: str, path: Optional[str] = None):
path = path or f"hf://facebook/{name}:{name}.pt"
if path.startswith("hf://"):
# Load from huggingface
path = path[len("hf://"):]
repo, file = path.split(":")
# To count the download, config.yaml is empty
hf_hub_download(repo_id=repo, filename="config.yaml")
return hf_hub_download(repo_id=repo, filename=file)
else:
return path
@dataclass
class PEConfig:
""" Vision Tower Config. """
patch_size: int
width: int
layers: int
heads: int
mlp_ratio: float
output_dim: Optional[int]
ls_init_value: float = None
drop_path: float = 0.0
image_size: int = 224,
use_abs_posemb: bool = True
use_cls_token: bool = False
use_rope2d: bool = True
pool_type: str = "attn"
attn_pooler_heads: int = 8
use_ln_pre: bool = True
use_ln_post: bool = True
@dataclass
class PETextConfig:
""" Text Tower Config. """
context_length: int
width: int
heads: int
layers: int
output_dim: int
mlp_ratio: float = 4.0
vocab_size: int = 49408
PE_VISION_CONFIG = {}
PE_TEXT_CONFIG = {}
#########################################
# PE CORE #
#########################################
PE_VISION_CONFIG["PE-Core-G14-448"] = PEConfig(
image_size=448,
patch_size=14,
width=1536,
layers=50,
heads=16,
mlp_ratio=8960 / 1536,
pool_type="attn",
output_dim=1280,
use_cls_token=False,
)
PE_TEXT_CONFIG["PE-Core-G14-448"] = PETextConfig(
context_length=72,
width=1280,
heads=20,
layers=24,
output_dim=1280
)
PE_VISION_CONFIG["PE-Core-L14-336"] = PEConfig(
image_size=336,
patch_size=14,
width=1024,
layers=24,
heads=16,
mlp_ratio=4.0,
pool_type="attn",
output_dim=1024,
use_cls_token=True,
)
PE_TEXT_CONFIG["PE-Core-L14-336"] = PETextConfig(
context_length=32,
width=1024,
heads=16,
layers=24,
output_dim=1024
)
PE_VISION_CONFIG["PE-Core-B16-224"] = PEConfig(
image_size=224,
patch_size=16,
width=768,
layers=12,
heads=12,
mlp_ratio=4.0,
pool_type="attn",
output_dim=1024,
use_cls_token=True,
)
PE_TEXT_CONFIG["PE-Core-B16-224"] = PE_TEXT_CONFIG["PE-Core-L14-336"]
#########################################
# PE Lang #
#########################################
PE_VISION_CONFIG["PE-Lang-G14-448"] = replace(
PE_VISION_CONFIG["PE-Core-G14-448"],
image_size=448,
pool_type="none",
use_ln_post=False,
output_dim=None,
ls_init_value=0.1,
layers=47,
)
PE_VISION_CONFIG["PE-Lang-L14-448"] = replace(
PE_VISION_CONFIG["PE-Core-L14-336"],
image_size=448,
pool_type="none",
use_ln_post=False,
output_dim=None,
ls_init_value=0.1,
layers=23
)
#########################################
# PE Spatial #
#########################################
PE_VISION_CONFIG["PE-Spatial-G14-448"] = replace(
PE_VISION_CONFIG["PE-Core-G14-448"],
image_size=448,
pool_type="none",
use_ln_post=False,
output_dim=None,
ls_init_value=0.1,
) |