# Copyright 2026 The HuggingFace Team and The Jeveration Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0. See the LICENSE and NOTICE files in this repository. # # Adapted from the Jeveration code (https://github.com/Carol-lyh/Jeveration, Apache-2.0): jeveration/pipeline.py. import torch from diffusers.modular_pipelines import ModularPipelineBlocks, PipelineState from diffusers.modular_pipelines.modular_pipeline_utils import ComponentSpec, InputParam, OutputParam from diffusers.utils.torch_utils import get_module_execution_device from .components import transformer_spec class JeverationDensePredictStep(ModularPipelineBlocks): model_name = "jeveration" @property def description(self) -> str: return ( "Step that predicts the raw per-pixel maps of every request row in one forward pass: segmentation logits, " "log-depth or surface normals, at the dense input size." ) @property def expected_components(self) -> list[ComponentSpec]: return [transformer_spec()] @property def inputs(self) -> list[InputParam]: return [ InputParam( "input_ids", required=True, type_hint=torch.Tensor, description="Request token ids `[rows, L]`." ), InputParam( "attention_mask", required=True, type_hint=torch.Tensor, description="Padding mask of the request ids." ), InputParam( "position_ids", required=True, type_hint=torch.Tensor, description="Rotary positions `[3, rows, L]`." ), InputParam( "pixel_values", required=True, type_hint=torch.Tensor, description="The resized pictures, uint8." ), InputParam("dense_rows", required=True, type_hint=list, description="The task of each request row."), ] @property def intermediate_outputs(self) -> list[OutputParam]: return [ OutputParam( "dense_maps", type_hint=dict, description="Task -> raw maps `[B, C, h, w]` of that task's rows, in order, at the dense input size.", ) ] @torch.no_grad() def __call__(self, components, state: PipelineState) -> PipelineState: block_state = self.get_block_state(state) transformer = components.transformer device = get_module_execution_device(transformer) block_state.dense_maps = transformer( input_ids=block_state.input_ids.to(device), attention_mask=block_state.attention_mask.to(device), position_ids=block_state.position_ids.to(device), pixel_values=block_state.pixel_values.to(device), dense_tasks=block_state.dense_rows, ).dense_maps self.set_block_state(state, block_state) return components, state