Update configuration_sailvl.py
#6
by
ctranslate2-4you
- opened
- configuration_sailvl.py +100 -0
configuration_sailvl.py
CHANGED
|
@@ -12,9 +12,109 @@ from .configuration_sailvit import SAILViTConfig
|
|
| 12 |
# from .configuration_qwen2 import Qwen2Config
|
| 13 |
from .configuration_qwen3 import Qwen3Config
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
logger = logging.get_logger(__name__)
|
| 16 |
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
class SAILVLConfig(PretrainedConfig):
|
| 19 |
model_type = 'sailvl'
|
| 20 |
is_composition = True
|
|
|
|
| 12 |
# from .configuration_qwen2 import Qwen2Config
|
| 13 |
from .configuration_qwen3 import Qwen3Config
|
| 14 |
|
| 15 |
+
logger = logging.get_logger(__name__)# --------------------------------------------------------
|
| 16 |
+
# adapted from internvl_chat/internvl/model/internvl_chat/configuration_internvl_chat.py
|
| 17 |
+
# --------------------------------------------------------
|
| 18 |
+
|
| 19 |
+
import copy
|
| 20 |
+
|
| 21 |
+
from transformers import LlamaConfig
|
| 22 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 23 |
+
from transformers.utils import logging
|
| 24 |
+
|
| 25 |
+
from .configuration_sailvit import SAILViTConfig
|
| 26 |
+
# from .configuration_qwen2 import Qwen2Config
|
| 27 |
+
from .configuration_qwen3 import Qwen3Config
|
| 28 |
+
|
| 29 |
logger = logging.get_logger(__name__)
|
| 30 |
|
| 31 |
|
| 32 |
+
class SAILVLConfig(PretrainedConfig):
|
| 33 |
+
model_type = 'sailvl'
|
| 34 |
+
is_composition = True
|
| 35 |
+
|
| 36 |
+
def __init__(
|
| 37 |
+
self,
|
| 38 |
+
vision_config=None,
|
| 39 |
+
llm_config=None,
|
| 40 |
+
use_backbone_lora=0,
|
| 41 |
+
use_llm_lora=0,
|
| 42 |
+
pad2square=False,
|
| 43 |
+
select_layer=-4,
|
| 44 |
+
force_image_size=None,
|
| 45 |
+
downsample_ratio=0.5,
|
| 46 |
+
template=None,
|
| 47 |
+
dynamic_image_size=False,
|
| 48 |
+
use_thumbnail=False,
|
| 49 |
+
ps_version='v1',
|
| 50 |
+
min_dynamic_patch=1,
|
| 51 |
+
max_dynamic_patch=6,
|
| 52 |
+
**kwargs
|
| 53 |
+
):
|
| 54 |
+
super().__init__(**kwargs)
|
| 55 |
+
|
| 56 |
+
if vision_config is None:
|
| 57 |
+
vision_config = {}
|
| 58 |
+
logger.info('vision_config is None. Initializing the SAILViTConfig with default values.')
|
| 59 |
+
|
| 60 |
+
if llm_config is None:
|
| 61 |
+
llm_config = {'architectures': ['Qwen3ForCausalLM']}
|
| 62 |
+
logger.info('llm_config is None. Initializing the Qwen3Config config with default values.')
|
| 63 |
+
|
| 64 |
+
self.vision_config = SAILViTConfig(**vision_config)
|
| 65 |
+
if llm_config['architectures'][0] == 'LlamaForCausalLM':
|
| 66 |
+
self.llm_config = LlamaConfig(**llm_config)
|
| 67 |
+
elif llm_config['architectures'][0] == 'Qwen3ForCausalLM':
|
| 68 |
+
self.llm_config = Qwen3Config(**llm_config)
|
| 69 |
+
else:
|
| 70 |
+
raise ValueError('Unsupported architecture: {}'.format(llm_config['architectures'][0]))
|
| 71 |
+
|
| 72 |
+
self.use_backbone_lora = use_backbone_lora
|
| 73 |
+
self.use_llm_lora = use_llm_lora
|
| 74 |
+
self.pad2square = pad2square
|
| 75 |
+
self.select_layer = select_layer
|
| 76 |
+
self.force_image_size = force_image_size
|
| 77 |
+
self.downsample_ratio = downsample_ratio
|
| 78 |
+
self.template = template
|
| 79 |
+
self.dynamic_image_size = dynamic_image_size
|
| 80 |
+
self.use_thumbnail = use_thumbnail
|
| 81 |
+
self.ps_version = ps_version # pixel shuffle version
|
| 82 |
+
self.min_dynamic_patch = min_dynamic_patch
|
| 83 |
+
self.max_dynamic_patch = max_dynamic_patch
|
| 84 |
+
|
| 85 |
+
logger.info(f'vision_select_layer: {self.select_layer}')
|
| 86 |
+
logger.info(f'ps_version: {self.ps_version}')
|
| 87 |
+
logger.info(f'min_dynamic_patch: {self.min_dynamic_patch}')
|
| 88 |
+
logger.info(f'max_dynamic_patch: {self.max_dynamic_patch}')
|
| 89 |
+
|
| 90 |
+
def to_dict(self):
|
| 91 |
+
"""
|
| 92 |
+
Serializes this instance to a Python dictionary. Override the default [`~PretrainedConfig.to_dict`].
|
| 93 |
+
|
| 94 |
+
Returns:
|
| 95 |
+
`Dict[str, any]`: Dictionary of all the attributes that make up this configuration instance,
|
| 96 |
+
"""
|
| 97 |
+
output = copy.deepcopy(self.__dict__)
|
| 98 |
+
|
| 99 |
+
output['vision_config'] = self.vision_config.to_dict()
|
| 100 |
+
output['llm_config'] = self.llm_config.to_dict()
|
| 101 |
+
output['model_type'] = self.__class__.model_type
|
| 102 |
+
output['use_backbone_lora'] = self.use_backbone_lora
|
| 103 |
+
output['use_llm_lora'] = self.use_llm_lora
|
| 104 |
+
output['pad2square'] = self.pad2square
|
| 105 |
+
output['select_layer'] = self.select_layer
|
| 106 |
+
output['force_image_size'] = self.force_image_size
|
| 107 |
+
output['downsample_ratio'] = self.downsample_ratio
|
| 108 |
+
output['template'] = self.template
|
| 109 |
+
output['dynamic_image_size'] = self.dynamic_image_size
|
| 110 |
+
output['use_thumbnail'] = self.use_thumbnail
|
| 111 |
+
output['ps_version'] = self.ps_version
|
| 112 |
+
output['min_dynamic_patch'] = self.min_dynamic_patch
|
| 113 |
+
output['max_dynamic_patch'] = self.max_dynamic_patch
|
| 114 |
+
|
| 115 |
+
return output
|
| 116 |
+
|
| 117 |
+
|
| 118 |
class SAILVLConfig(PretrainedConfig):
|
| 119 |
model_type = 'sailvl'
|
| 120 |
is_composition = True
|