Implementation:Predibase Lorax Flash Granite Modeling
| Knowledge Sources | |
|---|---|
| Domains | Model_Architecture, Inference |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Optimized IBM Granite transformer implementation for LoRax inference serving with flash attention, LoRA adapter support, and Granite-specific scaling multipliers. Extends the Flash Llama implementation.
Description
This module implements the IBM Granite architecture adapted for high-throughput inference in the LoRax serving framework. Granite extends the Llama architecture with additional scaling multipliers for embeddings, attention, residuals, and logits. The main components are:
- GraniteConfig -- Configuration class extending LlamaConfig with Granite-specific parameters: embedding_multiplier (scales token embeddings), logits_scaling (scales output logits), residual_multiplier (scales residual connections), and attention_multiplier (replaces the standard 1/sqrt(d) attention scaling). Also adds attention_bias and mlp_bias flags.
- FlashGraniteAttention -- Extends FlashLlamaAttention, overriding the softmax_scale with the configurable attention_multiplier and using a custom load_attention function that supports optional attention bias.
- GraniteMLP -- Extends LlamaMLP with optional bias support on gate_proj, up_proj, and down_proj projections. Uses fused gate-up projection with LoRA adapter support on GATE_PROJ, UP_PROJ, and DOWN_PROJ.
- FlashGraniteLayer -- Extends FlashLlamaLayer, applying the residual_multiplier to both attention and MLP outputs before adding them to the residual stream.
- FlashGraniteForCausalLM -- Extends FlashLlamaForCausalLM, applying the embedding_multiplier to the embedding weights at initialization and scaling output logits by logits_scaling during forward.
Usage
Used internally by the LoRax server when serving IBM Granite-based models. Loaded via the model registry when the model config type matches.
Code Reference
Source Location
- Repository: Predibase_Lorax
- File: server/lorax_server/models/custom_modeling/flash_granite_modeling.py
- Lines: 1-303
Signature
class FlashGraniteForCausalLM(FlashLlamaForCausalLM):
def __init__(self, prefix: str, config, weights, create_layer_fn=None):
...
def forward(
self,
input_ids: torch.Tensor,
position_ids: torch.Tensor,
cu_seqlen_prefill: Optional[torch.Tensor],
kv_cache: List[Tuple[torch.Tensor, torch.Tensor]],
block_tables: torch.Tensor,
slots: torch.Tensor,
seqlen: Seqlen,
max_s: int,
adapter_data: AdapterBatchData,
prefill_cache_indices: Optional[torch.Tensor] = None,
lm_head_indices: Optional[torch.Tensor] = None,
cross_attention_states: Optional[torch.Tensor] = None,
skip_lm_head: bool = False,
) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
...
Import
from lorax_server.models.custom_modeling.flash_granite_modeling import FlashGraniteForCausalLM
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| input_ids | torch.Tensor | Yes | Token IDs for the input sequence |
| position_ids | torch.Tensor | Yes | Position indices for rotary embeddings |
| cu_seqlen_prefill | Optional[torch.Tensor] | Yes | Cumulative sequence lengths for flash attention prefill; None during decode |
| kv_cache | List[Tuple[torch.Tensor, torch.Tensor]] | Yes | Key-value cache tensors for each layer |
| block_tables | torch.Tensor | Yes | Block tables for paged attention |
| slots | torch.Tensor | Yes | Slot indices for KV cache storage |
| seqlen | Seqlen | Yes | Sequence length information for the batch |
| max_s | int | Yes | Maximum sequence length in the batch |
| adapter_data | AdapterBatchData | Yes | LoRA adapter configuration for the batch |
| prefill_cache_indices | Optional[torch.Tensor] | No | Indices for selective cache prefilling |
| lm_head_indices | Optional[torch.Tensor] | No | Indices to select specific positions for LM head |
| cross_attention_states | Optional[torch.Tensor] | No | Cross-attention states (passed through to parent class) |
| skip_lm_head | bool | No | If True, return hidden states without applying the LM head |
Outputs
| Name | Type | Description |
|---|---|---|
| logits | torch.Tensor | Next-token logits over the vocabulary, scaled by logits_scaling (or hidden states if skip_lm_head is True) |
| speculative_logits | Optional[torch.Tensor] | Speculative decoding logits scaled by logits_scaling, or None |
Usage Examples
# Internal usage within LoRax server
from lorax_server.models.custom_modeling.flash_granite_modeling import FlashGraniteForCausalLM
# Model instantiated by model registry, not directly by users