Tools
compile_check
torchlinops.tools.compile_check profiles a user-provided linop with eager
execution versus torch.compile on a sample input. It always benchmarks the
wrapped operator (linop, linop.H, or linop.N), since that is what user code
calls in practice.
import torch
from torchlinops import NUFFT
from torchlinops.tools import compile_check
locs = torch.randn(4096, 2, device="cuda")
A = NUFFT(locs, (64, 64), output_shape=("K",))
x = torch.randn(64, 64, dtype=torch.complex64, device="cuda")
result = compile_check(A, x, variants=["forward", "adjoint"])
The sample input determines the device, dtype, and input shape. An
output-shaped sample is constructed independently for adjoint profiling.
variants defaults to ["forward", "adjoint"]; pass "normal" to include the
normal operator. The result includes:
- eager and compiled median times and speedup,
- numerical differences versus eager,
- graph-break count and locations (unless
fullgraph=True), - tensor shapes and byte sizes.
Autograd/backward profiling is not included yet. For full benchmark matrices, see the torch.compile benchmarks.
torchlinops.tools.compile_check
compile_check(
linop,
sample_input: Tensor,
variants: list[str] | tuple[str, ...] = (
"forward",
"adjoint",
),
*,
warmup: int = 5,
iters: int = 20,
fullgraph: bool = False,
explain_graph_breaks: bool = True,
print_results: bool = True,
) -> CompileCheckResult
Profile eager vs torch.compile for a user-provided linop.
This always benchmarks the wrapped operator (linop, linop.H, or
linop.N), which is what users call in practice. The sample input sets
the device, dtype, and input shape. An output-shaped sample is constructed
independently for adjoint profiling.
| PARAMETER | DESCRIPTION |
|---|---|
linop
|
Operator to profile.
TYPE:
|
sample_input
|
Input-shaped sample. Determines device, dtype, and shape.
TYPE:
|
variants
|
Variants to run. Accepts
TYPE:
|
warmup
|
Timing protocol for both eager and compiled calls.
TYPE:
|
iters
|
Timing protocol for both eager and compiled calls.
TYPE:
|
fullgraph
|
Passed to
TYPE:
|
explain_graph_breaks
|
Measure graph breaks with
TYPE:
|
print_results
|
Print a summary table before returning.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CompileCheckResult
|
Tensor sizes, timings, speedups, numerical differences, and break locations for each requested variant. |
Notes
Autograd/backward profiling is not included yet.
Source code in src/torchlinops/tools.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |