unitorch.cli.models.clip¤
ClipProcessor¤
Tip
core/process/clip
is the section for configuration of ClipProcessor.
Bases: ClipProcessor
Processor for the CLIP model.
Initialize the ClipProcessor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vocab_path |
str
|
The path to the vocabulary file. |
required |
merge_path |
str
|
The path to the BPE merge file. |
required |
vision_config_path |
str
|
The path to the vision configuration file. |
required |
max_seq_length |
int
|
The maximum sequence length. Defaults to 128. |
128
|
position_start_id |
int
|
The position start ID. Defaults to 0. |
0
|
Source code in src/unitorch/cli/models/clip/processing.py
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 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of ClipProcessor from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the processor's initialization arguments. |
Source code in src/unitorch/cli/models/clip/processing.py
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 |
|
ClipForPretrain¤
Tip
core/model/pretrain/clip
is the section for configuration of ClipForPretrain.
Bases: ClipForPretrain
CLIP model for pretraining.
Initialize the ClipForPretrain model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path |
str
|
The path to the model configuration file. |
required |
projection_dim |
int
|
The dimension of the projection head. Defaults to 512. |
512
|
freeze_base_model |
bool
|
Whether to freeze the base model. Defaults to True. |
True
|
gradient_checkpointing |
bool
|
Whether to use gradient checkpointing. Defaults to False. |
False
|
use_all_gather |
bool
|
Whether to use all_gather operation. Defaults to True. |
True
|
Source code in src/unitorch/cli/models/clip/modeling.py
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 |
|
forward ¤
forward(
input_ids: Tensor,
pixel_values: Tensor,
attention_mask: Optional[Tensor] = None,
position_ids: Optional[Tensor] = None,
)
Perform a forward pass through the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ids |
Tensor
|
Input token IDs. |
required |
pixel_values |
Tensor
|
Input pixel values. |
required |
attention_mask |
Tensor
|
Attention mask. Defaults to None. |
None
|
position_ids |
Tensor
|
Position IDs. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
LossOutputs |
The loss outputs. |
Source code in src/unitorch/cli/models/clip/modeling.py
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 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of ClipForPretrain from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
ClipForPretrain |
An instance of the ClipForPretrain model. |
Source code in src/unitorch/cli/models/clip/modeling.py
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 |
|
ClipForClassification¤
Tip
core/model/classification/clip
is the section for configuration of ClipForClassification.
Bases: ClipForClassification
CLIP model for classification.
Initialize the ClipForClassification model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path |
str
|
The path to the model configuration file. |
required |
projection_dim |
int
|
The dimension of the projection head. Defaults to 512. |
512
|
num_classes |
int
|
The number of output classes. Defaults to 1. |
1
|
freeze_base_model |
bool
|
Whether to freeze the base model. Defaults to True. |
True
|
gradient_checkpointing |
bool
|
Whether to use gradient checkpointing. Defaults to False. |
False
|
Source code in src/unitorch/cli/models/clip/modeling.py
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 |
|
forward ¤
forward(
input_ids: Tensor,
pixel_values: Tensor,
attention_mask: Optional[Tensor] = None,
position_ids: Optional[Tensor] = None,
)
Perform a forward pass through the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ids |
Tensor
|
Input token IDs. |
required |
pixel_values |
Tensor
|
Input pixel values. |
required |
attention_mask |
Tensor
|
Attention mask. Defaults to None. |
None
|
position_ids |
Tensor
|
Position IDs. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
ClassificationOutputs |
The classification outputs. |
Source code in src/unitorch/cli/models/clip/modeling.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of ClipForClassification from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
ClipForClassification |
An instance of the ClipForClassification model. |
Source code in src/unitorch/cli/models/clip/modeling.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
ClipForTextClassification¤
Tip
core/model/classification/clip/text
is the section for configuration of ClipForTextClassification.
Bases: ClipForTextClassification
CLIP model for text classification.
Initialize the ClipForTextClassification model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path |
str
|
The path to the model configuration file. |
required |
projection_dim |
int
|
The dimension of the projection head. Defaults to 512. |
512
|
num_classes |
int
|
The number of output classes. Defaults to 1. |
1
|
freeze_base_model |
bool
|
Whether to freeze the base model. Defaults to True. |
True
|
gradient_checkpointing |
bool
|
Whether to use gradient checkpointing. Defaults to False. |
False
|
Source code in src/unitorch/cli/models/clip/modeling.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
forward ¤
forward(
input_ids=None,
attention_mask: Optional[Tensor] = None,
position_ids: Optional[Tensor] = None,
)
Perform a forward pass through the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ids |
Tensor
|
Input token IDs. Defaults to None. |
None
|
attention_mask |
Tensor
|
Attention mask. Defaults to None. |
None
|
position_ids |
Tensor
|
Position IDs. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
ClassificationOutputs |
The classification outputs. |
Source code in src/unitorch/cli/models/clip/modeling.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of ClipForTextClassification from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
ClipForTextClassification |
An instance of the ClipForTextClassification model. |
Source code in src/unitorch/cli/models/clip/modeling.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
ClipForImageClassification¤
Tip
core/model/classification/clip/image
is the section for configuration of ClipForImageClassification.
Bases: ClipForImageClassification
CLIP model for image classification.
Initialize the ClipForImageClassification model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path |
str
|
The path to the model configuration file. |
required |
projection_dim |
int
|
The dimension of the projection head. Defaults to 512. |
512
|
num_classes |
int
|
The number of output classes. Defaults to 1. |
1
|
freeze_base_model |
bool
|
Whether to freeze the base model. Defaults to True. |
True
|
gradient_checkpointing |
bool
|
Whether to use gradient checkpointing. Defaults to False. |
False
|
Source code in src/unitorch/cli/models/clip/modeling.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
forward ¤
forward(pixel_values: Tensor)
Perform a forward pass through the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pixel_values |
Tensor
|
Input pixel values. |
required |
Returns:
Name | Type | Description |
---|---|---|
ClassificationOutputs |
The classification outputs. |
Source code in src/unitorch/cli/models/clip/modeling.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of ClipForImageClassification from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
ClipForImageClassification |
An instance of the ClipForImageClassification model. |
Source code in src/unitorch/cli/models/clip/modeling.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|