vllm.model_executor.models.adapters ¶
Functions:
-
as_embedding_model–Subclass an existing vLLM model to support embeddings.
-
as_seq_cls_model–Subclass an existing vLLM model to support classify and score tasks.
_disable_seq_cls_loading_on_inner_model(language_model, is_vlm) ¶
Context manager to temporarily disable sequence classification loading on inner VLM models to prevent recursive seq_cls_model_loader calls.
Source code in vllm/model_executor/models/adapters.py
_get_language_model_for_seq_cls(model) ¶
Get the language model component for sequence classification conversion. For VLMs, returns the inner language model. For standard LLMs, returns model itself.
Source code in vllm/model_executor/models/adapters.py
_load_dense_weights(linear, folder, model_config) ¶
Load weights using vLLM's weight_loader pattern.
Source code in vllm/model_executor/models/adapters.py
_load_st_projector(model_config) ¶
Load Sentence-Transformers Dense projection layers.
Source code in vllm/model_executor/models/adapters.py
_resolve_num_labels(hf_config, text_config) ¶
Resolve the label count for a sequence classification head.
PretrainedConfig.num_labels is derived from id2label, which always carries a default of two entries. Composite configs (such as multimodal checkpoints) declare their label space on the top-level config, so reading num_labels from get_text_config() silently returns that default and builds a score head of the wrong size.
Prefer the top-level config whenever it declares a label space of its own, mirroring the classifier_from_token / method lookups in as_seq_cls_model.
Source code in vllm/model_executor/models/adapters.py
as_embedding_model(cls) ¶
Subclass an existing vLLM model to support embeddings.
By default, the embeddings of the whole prompt are extracted from the normalized hidden state corresponding to the last token.
Note
We assume that no extra layers are added to the original model; please implement your own model if this is not the case.
Source code in vllm/model_executor/models/adapters.py
as_seq_cls_model(cls) ¶
Subclass an existing vLLM model to support classify and score tasks.
By default, the class probabilities are extracted from the softmaxed hidden state corresponding to the last token.
Note
We assume that the classification head is a single linear layer stored as the attribute score of the top-level model; please implement your own model if this is not the case.
Source code in vllm/model_executor/models/adapters.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 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 366 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 412 413 414 | |