Skip to content

vllm.model_executor.models.cohere_compass

Inference-only Cohere Compass model compatible with HuggingFace weights.

Classes:

CohereCompassForConditionalGeneration

Bases: Module, SupportsMultiModal, Qwen2VLEncoderCudaGraphMixin, SupportsLoRA, SupportsPP, SupportsMRoPE, SupportsEagle, SupportsEagle3, SupportsMultiModalPruning

Methods:

_postprocess_image_embeds_evs(image_embeds_split, image_input)

Append mrope positions for each for images. This is necessary to recover correct mrope positions

Parameters:

  • image_embeds_split

    (tuple[Tensor, ...]) –

    Tuple of image embeddings for each image item.

  • image_input

    (Cohere_VLImageInputs) –

    Image input data.

Returns:

  • Tensor –

    Tuple of image embeddings for each image item.

  • ... –

    Resulting embeddings will have extra 5 channels for

  • tuple[Tensor, ...] –

    computed mrope positions, consistent with video embeddings.

forward(input_ids, positions, intermediate_tensors=None, inputs_embeds=None, **kwargs)

Run forward pass for Cohere Compass.

Parameters:

  • input_ids

    (Tensor | None) –

    Flattened (concatenated) input_ids corresponding to a batch.

  • positions

    (Tensor) –

    Flattened (concatenated) position ids corresponding to a batch. NOTE: If mrope is enabled (default setting for Cohere Compass opensource models), the shape will be (3, seq_len), otherwise it will be (seq_len,).

  • intermediate_tensors

    (IntermediateTensors | None, default: None ) –

    Intermediate tensors from previous pipeline stages.

  • inputs_embeds

    (Tensor | None, default: None ) –

    Pre-computed input embeddings.

  • **kwargs

    (object, default: {} ) –

    Additional keyword arguments including: - pixel_values: Pixel values to be fed to a model. None if no images are passed. - image_grid_thw: Tensor (n_images, 3) of image 3D grid in LLM. None if no images are passed.

get_mm_mapping()

Get the module prefix in multimodal models

recompute_mrope_positions(input_ids, multimodal_embeddings, mrope_positions, num_computed_tokens)

Update part of input mrope positions (starting with num_computed_tokens index). Original mrope_positions are computed for unpruned sequence and becomes incorrect once pruning occurs, so once we prune media tokens we should reflect this in the mrope_positions before we feed it to LLM.

Parameters:

  • input_ids

    (list[int]) –

    (N,) All input tokens of the prompt containing entire sequence.

  • multimodal_embeddings

    (MultiModalEmbeddings) –

    Tuple of multimodal embeddings that fits into the prefill chunk that is being processed.

  • mrope_positions

    (LongTensor) –

    Existing mrope positions (3, N) for entire sequence

  • num_computed_tokens

    (int) –

    A number of computed tokens so far.

Returns:

Cohere_VLImageEmbeddingInputs

Bases: TensorSchema

Dimensions
  • nf: Number of image features
  • hs: Hidden size
  • ni: Number of images
Historical context
  • image_embeds shape: (num_image_features, hidden_size)
  • num_image_features varies based on the number and resolution of the images.
  • hidden_size must match the hidden size of language model backbone.
  • image_grid_thw shape: (num_images, 3) in (grid_t, grid_h, grid_w) format

Cohere_VLImagePixelInputs

Bases: TensorSchema

Dimensions
  • np: Number of patches
  • ni: Number of images
  • cps: Number of channels * patch_size * patch_size
Historical context
  • pixel_values shape: (num_patches, num_channels * patch_size * patch_size)
  • image_grid_thw shape: (num_images, 3) in (grid_t, grid_h, grid_w) format.

Cohere_VisionTransformer

Bases: Module

Methods:

prepare_encoder_metadata(grid_thw_list, *, max_batch_size=None, max_frames_per_batch=None, max_seqlen_override=None, device=None)

Compute encoder metadata from grid_thw_list.

Shared by the eager forward path, CUDA graph capture, and CUDA graph replay to avoid duplicated implementation.

Parameters:

  • grid_thw_list

    (list[list[int]]) –

    Grid configurations as list of [t, h, w].

  • max_batch_size

    (int | None, default: None ) –

    If set, pad cu_seqlens to this size (needed for CUDA graph capture/replay).

  • max_frames_per_batch

    (int | None, default: None ) –

    If set, overrides max_batch_size for cu_seqlens padding. For video inputs each item contributes T attention sequences (frames); this sizes the buffer to the total frame budget so video replays never overflow.

  • max_seqlen_override

    (int | None, default: None ) –

    If set, use this value for max_seqlen instead of computing from cu_seqlens (needed for CUDA graph capture to cover worst-case replay scenarios).

  • device

    (device | None, default: None ) –

    Device to place tensors on. Defaults to self.device.

_bilinear_pos_embed_kernel(embed_ptr, output_ptr, H, W, h_scale, w_scale, NUM_GRID, M_SIZE, HIDDEN_DIM, BLOCK_D)

Fused bilinear pos-embed interpolation with spatial-merge reorder.

pos_embed_interpolate_native(embed_weight, t, h, w, num_grid_per_side, m_size, dtype)

Eager PyTorch bilinear position-embedding interpolation.

Returns a tensor of shape (t * h * w, hidden_dim) with the bilinearly-interpolated position embeddings in spatial-merge order.

triton_pos_embed_interpolate(embed_weight, t, h, w, num_grid_per_side, m_size, dtype)

Launch the fused Triton kernel for one (t,h,w) grid.

Returns a tensor of shape (t * h * w, hidden_dim) with the bilinearly-interpolated position embeddings in spatial-merge order.