Delete configuration_prismatic.py.back.20260315_133310
Browse files
configuration_prismatic.py.back.20260315_133310
DELETED
|
@@ -1,145 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
configuration_prismatic.py
|
| 3 |
-
|
| 4 |
-
HuggingFace-style configuration definition for Prismatic VLMs, inheriting from `transformers.PretrainedConfig`.
|
| 5 |
-
Default configuration specifies `siglip-224px+7b`.
|
| 6 |
-
"""
|
| 7 |
-
|
| 8 |
-
from typing import Any, Dict, List, Optional
|
| 9 |
-
|
| 10 |
-
from transformers import PretrainedConfig
|
| 11 |
-
from transformers.models.auto import CONFIG_MAPPING
|
| 12 |
-
|
| 13 |
-
# === Utilities for Mapping Prismatic names to HF names ===
|
| 14 |
-
# fmt: off
|
| 15 |
-
VISION_BACKBONE_TO_RESOLUTION: Dict[str, List[int]] = {
|
| 16 |
-
"clip-vit-l": [224], "siglip-vit-so400m": [224], "dinov2-vit-l": [224], "in1k-vit-l": [224],
|
| 17 |
-
|
| 18 |
-
"clip-vit-l-336px": [336],
|
| 19 |
-
"siglip-vit-so400m-384px": [384],
|
| 20 |
-
|
| 21 |
-
"dinoclip-vit-l-336px": [336, 336],
|
| 22 |
-
"dinosiglip-vit-so-224px": [224, 224],
|
| 23 |
-
"dinosiglip-vit-so-384px": [384, 384],
|
| 24 |
-
}
|
| 25 |
-
VISION_BACKBONE_TO_TIMM_ID: Dict[str, List[str]] = {
|
| 26 |
-
"clip-vit-l": ["vit_large_patch14_clip_224.openai"],
|
| 27 |
-
"clip-vit-l-336px": ["vit_large_patch14_clip_336.openai"],
|
| 28 |
-
|
| 29 |
-
"dinov2-vit-l": ["vit_large_patch14_reg4_dinov2.lvd142m"],
|
| 30 |
-
"in1k-vit-l": ["vit_large_patch16_224.augreg_in21k_ft_in1k"],
|
| 31 |
-
|
| 32 |
-
"siglip-vit-so400m": ["vit_so400m_patch14_siglip_224"],
|
| 33 |
-
"siglip-vit-so400m-384px": ["vit_so400m_patch14_siglip_384"],
|
| 34 |
-
|
| 35 |
-
"dinoclip-vit-l-336px": ["vit_large_patch14_reg4_dinov2.lvd142m", "vit_large_patch14_clip_336.openai"],
|
| 36 |
-
"dinosiglip-vit-so-224px": ["vit_large_patch14_reg4_dinov2.lvd142m", "vit_so400m_patch14_siglip_224"],
|
| 37 |
-
"dinosiglip-vit-so-384px": ["vit_large_patch14_reg4_dinov2.lvd142m", "vit_so400m_patch14_siglip_384"],
|
| 38 |
-
}
|
| 39 |
-
TIMM_OVERRIDE_ACT_LAYER: Dict[str, List[Optional[str]]] = {
|
| 40 |
-
"clip-vit-l": ["quick_gelu"], "clip-vit-l-336px": ["quick_gelu"],
|
| 41 |
-
"dinov2-vit-l": [None], "in1k-vit-l": [None],
|
| 42 |
-
"siglip-vit-so400m": [None], "siglip-vit-so400m-384px": [None],
|
| 43 |
-
"dinoclip-vit-l-336px": [None, "quick_gelu"],
|
| 44 |
-
"dinosiglip-vit-so-224px": [None, None], "dinosiglip-vit-so-384px": [None, None]
|
| 45 |
-
}
|
| 46 |
-
|
| 47 |
-
LLM_BACKBONE_TO_HF_PATH = {
|
| 48 |
-
"llama2-7b-pure": "meta-llama/Llama-2-7b-hf", "llama2-13b-pure": "meta-llama/Llama-2-13b-hf",
|
| 49 |
-
"llama2-7b-chat": "meta-llama/Llama-2-7b-chat-hf", "llama2-13b-chat": "meta-llama/Llama-2-13b-chat-hf",
|
| 50 |
-
|
| 51 |
-
"vicuna-v15-7b": "lmsys/vicuna-7b-v1.5", "vicuna-v15-13b": "lmsys/vicuna-13b-v1.5",
|
| 52 |
-
|
| 53 |
-
"mistral-v0.1-7b-pure": "mistralai/Mistral-7B-v0.1",
|
| 54 |
-
"mistral-v0.1-7b-instruct": "mistralai/Mistral-7B-Instruct-v0.1",
|
| 55 |
-
|
| 56 |
-
"phi-2-3b": "microsoft/phi-2",
|
| 57 |
-
"qwen25-0_5b-extra": "Qwen/Qwen2.5-0.5B", "qwen25-0_5b-pure": "Qwen/Qwen2.5-0.5B"
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
}
|
| 61 |
-
LLM_BACKBONE_TO_HF_METACLASS = {
|
| 62 |
-
"llama2-7b-pure": "llama", "llama2-13b-pure": "llama", "llama2-7b-chat": "llama", "llama2-13b-chat": "llama",
|
| 63 |
-
"vicuna-v15-7b": "llama", "vicuna-v15-13b": "llama",
|
| 64 |
-
|
| 65 |
-
"mistral-v0.1-7b-pure": "mistral", "mistral-v0.1-7b-instruct": "mistral",
|
| 66 |
-
|
| 67 |
-
"phi-2-3b": "phi",
|
| 68 |
-
"qwen25-0_5b-extra": "qwen2" ,"qwen25-0_5b-pure": "qwen2"
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
VALID_VISION_BACKBONES = set(VISION_BACKBONE_TO_RESOLUTION.keys())
|
| 72 |
-
VALID_LLM_BACKBONES = set(LLM_BACKBONE_TO_HF_PATH)
|
| 73 |
-
# fmt: on
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
class PrismaticConfig(PretrainedConfig):
|
| 77 |
-
model_type: str = "prismatic"
|
| 78 |
-
is_composition: bool = False
|
| 79 |
-
|
| 80 |
-
def __init__(
|
| 81 |
-
self,
|
| 82 |
-
vision_backbone_id: str = "siglip-vit-so400m",
|
| 83 |
-
llm_backbone_id: str = "vicuna-v15-7b",
|
| 84 |
-
arch_specifier: str = "no-align+gelu-mlp",
|
| 85 |
-
use_fused_vision_backbone: Optional[bool] = None,
|
| 86 |
-
image_resize_strategy: str = "letterbox",
|
| 87 |
-
text_config: Optional[Dict[str, Any]] = None,
|
| 88 |
-
llm_max_length: int = 2048,
|
| 89 |
-
pad_token_id: int = 32000,
|
| 90 |
-
pad_to_multiple_of: int = 64,
|
| 91 |
-
output_projector_states: bool = False,
|
| 92 |
-
**kwargs: str,
|
| 93 |
-
) -> None:
|
| 94 |
-
if vision_backbone_id not in VALID_VISION_BACKBONES:
|
| 95 |
-
raise ValueError(f"Vision backbone `{vision_backbone_id}` not in {VALID_VISION_BACKBONES = }")
|
| 96 |
-
|
| 97 |
-
if llm_backbone_id not in VALID_LLM_BACKBONES:
|
| 98 |
-
raise ValueError(f"LLM backbone `{llm_backbone_id}` not in {VALID_LLM_BACKBONES = }")
|
| 99 |
-
|
| 100 |
-
# Set Prismatic Configuration Fields
|
| 101 |
-
self.vision_backbone_id = vision_backbone_id
|
| 102 |
-
self.llm_backbone_id = llm_backbone_id
|
| 103 |
-
self.arch_specifier = arch_specifier
|
| 104 |
-
self.output_projector_states = output_projector_states
|
| 105 |
-
|
| 106 |
-
# [Contract] All vision backbone parameters are lists =>> supports fused backbones with different preprocessing
|
| 107 |
-
self.use_fused_vision_backbone = (
|
| 108 |
-
use_fused_vision_backbone
|
| 109 |
-
if use_fused_vision_backbone is not None
|
| 110 |
-
else any(self.vision_backbone_id.startswith(v) for v in ["dinoclip", "dinosiglip"])
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
-
self.timm_model_ids = VISION_BACKBONE_TO_TIMM_ID[self.vision_backbone_id]
|
| 114 |
-
self.timm_override_act_layers = TIMM_OVERRIDE_ACT_LAYER[self.vision_backbone_id]
|
| 115 |
-
self.image_sizes = VISION_BACKBONE_TO_RESOLUTION[self.vision_backbone_id]
|
| 116 |
-
self.image_resize_strategy = image_resize_strategy
|
| 117 |
-
|
| 118 |
-
self.hf_llm_id = LLM_BACKBONE_TO_HF_PATH[self.llm_backbone_id]
|
| 119 |
-
self.llm_max_length = llm_max_length
|
| 120 |
-
self.pad_token_id, self.pad_to_multiple_of = pad_token_id, pad_to_multiple_of
|
| 121 |
-
|
| 122 |
-
# [IMPORTANT] HF Utilities actually look for a `text_config` field... we need to use that specific naming!
|
| 123 |
-
self.text_config = (
|
| 124 |
-
CONFIG_MAPPING[LLM_BACKBONE_TO_HF_METACLASS[self.llm_backbone_id]](**text_config)
|
| 125 |
-
if text_config is not None
|
| 126 |
-
else CONFIG_MAPPING[LLM_BACKBONE_TO_HF_METACLASS[self.llm_backbone_id]]()
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
# Dispatch **kwargs to super() =>> note that `pad_token_id` collides, so we pass it in here as well...
|
| 130 |
-
super().__init__(pad_token_id=pad_token_id, **kwargs)
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
class OpenVLAConfig(PrismaticConfig):
|
| 134 |
-
model_type: str = "openvla"
|
| 135 |
-
|
| 136 |
-
def __init__(
|
| 137 |
-
self,
|
| 138 |
-
norm_stats: Optional[Dict[str, Dict[str, Dict[str, Dict[str, List[float]]]]]] = None,
|
| 139 |
-
n_action_bins: int = 256,
|
| 140 |
-
**kwargs: str,
|
| 141 |
-
) -> None:
|
| 142 |
-
self.norm_stats, self.n_action_bins = norm_stats, n_action_bins
|
| 143 |
-
self.use_reg_version = False
|
| 144 |
-
|
| 145 |
-
super().__init__(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|