In this repo, what models create a scalar tensor (with only one element) on GPU?
- User
In this repo, what models create a scalar tensor (with only one element) on GPU?
Assistant
I will search for code patterns in the
comfy/directory andnodes.pythat create a PyTorch tensor with a specific device argument, looking for instances where a scalar value (single element) is likely being created on the GPU.Assistant
I will read
comfy/model_base.pyto identify which models or methods create scalar tensors on the GPU, specifically examining lines 397, 613, and 1053. I will also examinecomfy/ldm/pixart/pixartms.pyandcomfy/ldm/hidream/model.pyto confirm the behavior in PixArt MS and HiDream models.Assistant
I will read
comfy/ldm/flux/controlnet.pyto determine the data type ofcontrol_typeand confirm if it results in a scalar tensor creation on the GPU.Assistant
The following models in the codebase create a scalar tensor (or a 1-element tensor) on the GPU, often during their conditioning or forward pass:
- PixArt (PixArtMS): If the aspect ratio conditioning (
c_ar) is not provided, it creates a 1-element tensor fallback on the GPU:torch.tensor([H/W], dtype=x.dtype, device=x.device). - SD X4 Upscaler: Creates a
noise_leveltensor on the GPU:noise_level = torch.tensor([noise_level], device=device). - Cosmos Video / Cosmos Predict: Creates a
sigma_noise_augmentationtensor on the GPU during inpainting scaling:torch.tensor([sigma_noise_augmentation], device=latent_image.device, ...). - HiDream: Creates a
timestepstensor on the GPU if the input is a scalar:torch.tensor([timesteps], dtype=dtype, device=device). - Flux ControlNet (Union): When using union control modes, it creates a tensor from
control_typeon the GPU: .
- PixArt (PixArtMS): If the aspect ratio conditioning (
- User
Is there any code that creates a scalar tensor on GPU and does comparison with it?
Assistant
I will read
comfy/extra_samplers/uni_pc.pyandcomfy/ldm/hunyuan3d/vae.pyto investigate if the scalar tensors created there are involved in comparisons. I will also perform a regex search fortorch.tensorcreation on a device followed by comparison operators or functions liketorch.eqortorch.whereto identify other potential instances.Assistant
I will search for code creating a tensor on a specific device using
torch.tensorwith a scalar or single-element list, and I will request 3 lines of context to identify if these tensors are subsequently involved in any comparison operations.Assistant
I will read
comfy/ldm/mmaudio/vae/alias_free_torch.pyandcomfy/ldm/lightricks/symmetric_patchifier.pyto examine the usage of scalar tensors created therein. I will also perform a regex search forifstatements containingtorch.tensorto identify potentially blocking comparisons.Assistant
I will read
comfy/text_encoders/qwen_vl.pyandcomfy/model_base.pyto trace the usage ofgrid_thwandnoise_levelrespectively, specifically checking for any subsequent comparisons involving these tensors.Assistant
I will search for
torch.tensorusage innodes.pyandcomfy_extras/to identify any instances where scalar tensors created on the GPU are subsequently used in comparisons.Assistant
I will search for
torch.tensorinnodes.pyto identify any tensor creations that might be relevant to the user's query about scalar tensors on the GPU and comparisons.Assistant
I will search for
torch.tensorin thecomfy/ldm/flux/directory to identify any relevant usage of tensor creation in that module.Assistant
I will read
comfy/ldm/audio/embedders.pyto examine theNumberConditionerclass and how it processes input values, specifically checking ifxis converted to a scalar tensor on the GPU and if any comparisons are performed on it.Assistant
I will read
comfy/ldm/flux/math.pyandcomfy/ldm/flux/layers.pyto check for anytorch.tensorusage or comparisons that might fit the description of creating a scalar tensor on the GPU and comparing it.Assistant
I will search for
torch.tensorincomfy/model_sampling.pyandcomfy/ldm/modules/diffusionmodules/mmdit.pyto check for any relevant tensor creations and comparisons.Assistant
Based on the analysis of the codebase, there are a few instances where a scalar tensor (or a 1-element tensor) is created on the GPU and used in close proximity to a comparison or conditional operation.
The most prominent example where a (0-d tensor) is explicitly created on the GPU and used in a conditional operation (specifically ) is in .