Keyword arguments are silently ignored when a decorated function is called without positional arguments

Aperta Adatta ai principianti
#88 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
performance

Direzione di ricerca

Inizia da nsight/collection/core.py e segui la gestione della configurazione al momento della chiamata attorno a _sanitize_configs e al controllo if len(args) > 0. Leggi test_config_at_call_time_with_kwargs e aggiungi test per una chiamata con soli argomenti nominati, come bench(n=4096). Il lavoro è concluso quando gli argomenti nominati vengono usati come configurazione oppure generano in modo coerente la ProfilerException documentata, senza ripiegare silenziosamente sul valore predefinito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

Calling a function decorated with @nsight.analyze.kernel with only keyword arguments drops them. The call is profiled with the parameter default (or with the decorator-time configs), and the results report that configuration instead of the requested one. No error or warning is raised.

import nsight
import torch

@nsight.analyze.kernel
def bench(n: int = 64) -> None:
    a = torch.randn(n, n, device="cuda")
    b = torch.randn(n, n, device="cuda")
    with nsight.annotate("add"):
        _ = a + b

df = bench(n=4096).to_dataframe()
print(df[["Annotation", "n", "Metric"]])   # n is 64, not 4096

The same happens with @nsight.analyze.kernel(configs=[(64,)]) and bench(n=4096).

bench(42, y=23) already raises ProfilerException: Keyword arguments are not supported yet: ['y'] (_sanitize_configs in nsight/collection/core.py, tested by test_config_at_call_time_with_kwargs). That check sits inside if len(args) > 0:, so it is skipped when there are no positional arguments.

Expected

The same ProfilerException, or the keyword arguments being used as the configuration.

Environment

nsight-python main at c89d4b5, Python 3.12.3, Linux x86_64.

How this was checked: no GPU was available, so the profiling backend was replaced by a mock (NVTX ranges and NCUCollector.collect). Config handling, the run loop, extraction and aggregation were the real nsight code. An equivalent script with the kernel launch stubbed out shows n=64 in the results for both cases (requested n=4096, profiled n=64). It has not been run on a GPU with NCU or CUPTI.

A small fix is ready if you approve it: move the existing check out of the if len(args) > 0: block, so keyword arguments raise the same ProfilerException on every call, and add a test next to test_config_at_call_time_with_kwargs. That turns today's silent wrong result into an error for callers who use bench(n=...). Supporting keyword arguments instead would be your call.

This was found with an AI coding assistant (Claude Code, claude-fable-5-2), which also wrote and ran the mocked repro and drafted this report.

Lingua principale
Python
Stelle
301
Fork
23
Merge medio
2g 20h
PR unite (30g)
12

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NVIDIA/nsight-python

Tutte le issue di NVIDIA/nsight-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.