[Bug] TorchDist.recv allocates a temporary tensor instead of writing into the caller's NumPy buffer in-place
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Área
- distributed-systems
Línea de trabajo
Read tensorrt_llm/_torch/distributed/communicator.py around TorchDist.recv and check any tests covering NumPy buffer receives. The issue includes a two process reproduction using Gloo; run it to confirm whether the caller's buffer changes. Done means received data is visible in the supplied buffer, with any relevant receive tests passing; a linked pull request is already open for this issue.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
In tensorrt_llm/_torch/distributed/communicator.py (commit 1aa0192e62d219599930f125ada7067081fb44b7, present at HEAD), TorchDist.recv is annotated # in-place recv numpy buffer, yet allocates a disconnected temporary tensor with torch.empty_like(torch.from_numpy(buf)) instead of receiving into torch.from_numpy(buf):
# tensorrt_llm/_torch/distributed/communicator.py:1577-1593
@log_op
def isend(self, buf: np.ndarray, dest, tag=0):
# non-blocking send numpy buffer
tensor = torch.from_numpy(buf)
return dist.isend(tensor, dst=dest, tag=tag)
@log_op
def recv(self, buf: np.ndarray, src, tag=0):
# in-place recv numpy buffer
tensor = torch.empty_like(torch.from_numpy(buf))
dist.recv(tensor, src=src, tag=tag)
return tensor.numpy()
Because torch.empty_like(...) allocates a fresh tensor that does not share memory with buf, dist.recv(tensor, ...) writes received bytes into the temporary tensor and leaves the caller's buf untouched (e.g., all zeros). Any caller that discards the return value and expects buf to be populated in-place (matching # in-place recv numpy buffer and MPI Recv(buf) semantics) silently operates on stale/zeroed data without error.
Affected Location
- Repository:
NVIDIA/TensorRT-LLM(1aa0192e62d219599930f125ada7067081fb44b7, present atHEAD) - File & lines:
tensorrt_llm/_torch/distributed/communicator.py:1587-1593(TorchDist.recv)
Minimal Standalone Reproduction
import datetime, socket
import numpy as np
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
from tensorrt_llm._torch.distributed.communicator import TorchDist
def free_port():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("127.0.0.1", 0))
return s.getsockname()[1]
def worker(rank, port):
dist.init_process_group(
"gloo", init_method=f"tcp://127.0.0.1:{port}", rank=rank, world_size=2,
timeout=datetime.timedelta(seconds=5),
)
td = TorchDist.__new__(TorchDist)
td.mapping = None
if rank == 0:
td.isend(np.array([11, 22, 33, 44], dtype=np.int64), dest=1, tag=7).wait()
else:
recv_buf = np.zeros(4, dtype=np.int64)
ret = td.recv(recv_buf, src=0, tag=7)
print("caller recv_buf:", recv_buf.tolist(), "returned:", ret.tolist())
assert np.array_equal(recv_buf, ret), f"Expected in-place update, got {recv_buf}"
dist.destroy_process_group()
if __name__ == "__main__":
mp.spawn(worker, args=(free_port(),), nprocs=2, join=True)
Observed output:
caller recv_buf: [0, 0, 0, 0] returned: [11, 22, 33, 44]
AssertionError: Expected in-place update, got [0 0 0 0]
Suggested Fix
Receive directly into the backing storage of buf via torch.from_numpy(buf) (if contiguous, or copy back into buf if non-contiguous):
@log_op
def recv(self, buf: np.ndarray, src, tag=0):
# in-place recv numpy buffer
tensor = torch.from_numpy(buf)
dist.recv(tensor, src=src, tag=tag)
return buf
(If buf may be non-contiguous where torch.from_numpy or dist.recv requires contiguous storage, copy tensor.numpy() back into buf[:] before returning buf.)
- Lenguaje dominante
- Python
- Estrellas
- 15.2k
- Forks
- 3k
- Merge medio
- 2 d 21 h
- PR fusionados (30 d)
- 477
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de NVIDIA/TensorRT-LLM
-
Bug: AttributeError: 'GptOssConfig' object has no attribute 'rope_scaling_factor' with transformers >= 5.xPosiblemente ocupada @NimaVaziri la tomó hoy. AbiertoPytorch
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NVIDIA/TensorRT-LLM#23406 ·
Los mantenedores suelen responder en 1 día
-
Inference runtime Windows
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
NVIDIA/TensorRT-LLM#23394 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: MMLU subsampling changes when evaluators are interleavedPosiblemente ocupada @LeNeLeNeWo la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
NVIDIA/TensorRT-LLM#23273 ·
Los mantenedores suelen responder en 1 día
-
Trace-replay Pareto window includes the drain when sessions finish out of admission orderPosiblemente ocupada @sbeierle la tomó hace 3 días. AbiertoTesting
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
NVIDIA/TensorRT-LLM#23077 ·
Los mantenedores suelen responder en 1 día
-
LongBench V2 blog command breaks on inline comments after continuationsPosiblemente ocupada @ddlw la tomó hace 26 días. AbiertoDoc
Dificultad 1/5 Menos de una hora Aptitud para principiantes 91/100
NVIDIA/TensorRT-LLM#21879 ·
Los mantenedores suelen responder en 1 día
Todos los issues de NVIDIA/TensorRT-LLM
Issues similares
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionErrorPosiblemente ocupada @jejjohnson la tomó hoy. Abiertotype:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
jejjohnson/integrix#144 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
finos/ai-governance-framework#459 ·
-
slurm: a case outcome nested too deep crashes status/collect instead of reading as no outcomeAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
freelawproject/litigant-portal#1307 ·
Los mantenedores suelen responder en 2 días
-
type/bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
h2oai/h2o-llmstudio#1163 ·
Los mantenedores suelen responder en 1 día