|
249 | 249 | "NVTE_DEBUG = 0/1 # disables/enables debugging\n", |
250 | 250 | "NVTE_DEBUG_LEVEL = 0/1/2 # enables logging.WARNING/INFO/DEBUG-level messages\n", |
251 | 251 | "```\n", |
252 | | - "<div class=\"alert alert-info\">\n", |
253 | | - "<b>Note:</b>\n", |
254 | | - " \n", |
255 | | - "These flags are supported in PyTorch only as of Transformer Engine 2.0. JAX support is expected to be added in the future.\n", |
256 | | - "</div>" |
| 252 | + "These flags are available in both PyTorch and Jax in TE v2.20 onwards." |
257 | 253 | ] |
258 | 254 | }, |
259 | 255 | { |
|
330 | 326 | "!NVTE_DEBUG=1 NVTE_DEBUG_LEVEL=2 python example_attention.py" |
331 | 327 | ] |
332 | 328 | }, |
| 329 | + { |
| 330 | + "cell_type": "markdown", |
| 331 | + "id": "fc0c9e3d", |
| 332 | + "metadata": {}, |
| 333 | + "source": [ |
| 334 | + "For the FusedAttention backend, cuDNN graphs are cached and reused, and the following flag helps understand the activities taking place in the cache. `NVTE_FUSED_ATTN_CACHE_DEBUG` is supported in both PyTorch and JAX.\n", |
| 335 | + "```\n", |
| 336 | + "NVTE_FUSED_ATTN_CACHE_DEBUG = 0 # disables cache diagnostics\n", |
| 337 | + "NVTE_FUSED_ATTN_CACHE_DEBUG = 1/2:ranks # enables cache diagnostics (events)/(tracing):select ranks for information collection\n", |
| 338 | + "```\n", |
| 339 | + "At level 1, these cache events are collected and reported in the end-of-run summary: `create_graph` (number of graphs created), `cache_graph` (number of graphs cached), `hit` (number of cache hits), `miss` (number of cache misses), `build_plans` (number of graphs whose plans are built), and `execute` (number of plan executions). These event counters are tallied up per backend (f16 and fp8), per pass (forward and backward), and per thread. They help paint a picture of the graph reuse rate and caching effectiveness. Another part of the end-of-run summary are the build times of various stages of the cuDNN graph. Out of the 5 cuDNN calls, `validate`, `build_operation_graph`, `create_execution_plans`, `check_support`, and `build_plans`, `build_plans` is the most expensive one, because it is where the kernels get compiled. It happens once per eligible graph and is expected to execute many times in a real-life run.\n", |
| 340 | + "\n", |
| 341 | + "For more verbose diagnostics, level 2 enables tracing for all the events taking place in the cache. For example, for every `miss` event, a \"MISS\" line is printed in the logs, as well as the cache key that triggered it. This helps identify if the cache is processing the right config as we intended.\n", |
| 342 | + "\n", |
| 343 | + "By default, only rank 0 is enabled for both level 1 and level 2. Users can use the \"level:ranks\" format to specify a select set of ranks to collect diagnostics on. For example, \"2:0,3\" means to enable level 2 diagnostics on ranks 0 and 3. An example of the level 2 diagnostics, which also includes the level 1 summary, is as follows, for a `tests/pytorch/attention/test_attention.py::test_dot_product_attention` test.\n", |
| 344 | + "```\n", |
| 345 | + "[FUSED-ATTN-CACHE] rank=0 | tid=0 dev=0 | f16 fwd MISS | train=1 det=0 cg=0 maxlogit=0 mask=0 bias=0 wl=-1 wr=-1 brd=0 softmax=0 scale_mode=0 dropout=0 attn_scale=1 qkv_dt=5 o_dt=5 do_dt=6 dqkv_dt=6 qkv_lay=0 o_fmt=0 do_fmt=8 dqkv_lay=26 qkv_sif=8 do_sif=8 b=8 h=16 hg=16 dqk=64 dv=64 sq=128 skv=128 tq=0 tkv=0 bb=0 btq=0 btkv=0 npk=0 npv=0 psk=0 psv=0 mppk=0 mppv=0 bias_b=0 bias_h=0 bias_sq=0 bias_skv=0\n", |
| 346 | + "[FUSED-ATTN-CACHE] rank=0 | tid=0 dev=0 | f16 fwd CREATE_GRAPH | hit= 0, miss= 1, create_graph= 1, cache_graph= 0, build_plans= 0, execute= 0\n", |
| 347 | + "[FUSED-ATTN-CACHE] rank=0 | tid=0 dev=0 | f16 fwd CACHE_GRAPH | hit= 0, miss= 1, create_graph= 1, cache_graph= 1, build_plans= 0, execute= 0\n", |
| 348 | + "...\n", |
| 349 | + "[FUSED-ATTN-CACHE] rank=0 | tid=0 dev=0 | f16 fwd HIT | train=1 det=0 cg=0 maxlogit=0 mask=0 bias=0 wl=-1 wr=-1 brd=0 softmax=0 scale_mode=0 dropout=0 attn_scale=1 qkv_dt=5 o_dt=5 do_dt=6 dqkv_dt=6 qkv_lay=0 o_fmt=0 do_fmt=8 dqkv_lay=26 qkv_sif=8 do_sif=8 b=8 h=16 hg=16 dqk=64 dv=64 sq=128 skv=128 tq=0 tkv=0 bb=0 btq=0 btkv=0 npk=0 npv=0 psk=0 psv=0 mppk=0 mppv=0 bias_b=0 bias_h=0 bias_sq=0 bias_skv=0\n", |
| 350 | + "[FUSED-ATTN-CACHE] rank=0 | tid=0 dev=0 | f16 fwd BUILD_PLANS | hit= 3, miss= 1, create_graph= 1, cache_graph= 1, build_plans= 1, execute= 0\n", |
| 351 | + "...\n", |
| 352 | + "[FUSED-ATTN-CACHE] rank=0 | tid=0 dev=0 | f16 fwd EXECUTE | hit= 5, miss= 1, create_graph= 1, cache_graph= 1, build_plans= 1, execute= 1\n", |
| 353 | + "...\n", |
| 354 | + "[FUSED-ATTN-CACHE] rank=0 | ===== summary begin =====\n", |
| 355 | + "[FUSED-ATTN-CACHE] rank=0 | tid=0 dev=0 | f16 fwd | hit= 5, miss= 1, create_graph= 1, cache_graph= 1, build_plans= 1, execute= 1\n", |
| 356 | + "[FUSED-ATTN-CACHE] rank=0 | tid=0 dev=0 | f16 bwd | hit= 1, miss= 1, create_graph= 1, cache_graph= 1, build_plans= 0, execute= 0\n", |
| 357 | + "[FUSED-ATTN-CACHE] rank=0 | tid=1 dev=0 | f16 bwd | hit= 4, miss= 0, create_graph= 0, cache_graph= 0, build_plans= 1, execute= 1\n", |
| 358 | + "[FUSED-ATTN-CACHE] rank=0 | tid=all dev=all | f16 fwd | hit= 5, miss= 1, create_graph= 1, cache_graph= 1, build_plans= 1, execute= 1\n", |
| 359 | + "[FUSED-ATTN-CACHE] rank=0 | tid=all dev=all | f16 bwd | hit= 5, miss= 1, create_graph= 1, cache_graph= 1, build_plans= 1, execute= 1\n", |
| 360 | + "[FUSED-ATTN-CACHE] rank=0 | f16 fwd validate | calls=1 | time= 0.168 ms/call\n", |
| 361 | + "[FUSED-ATTN-CACHE] rank=0 | f16 fwd build_operation_graph | calls=1 | time= 11.405 ms/call\n", |
| 362 | + "[FUSED-ATTN-CACHE] rank=0 | f16 fwd create_execution_plans | calls=1 | time= 2.054 ms/call\n", |
| 363 | + "[FUSED-ATTN-CACHE] rank=0 | f16 fwd check_support | calls=1 | time= 0.044 ms/call\n", |
| 364 | + "[FUSED-ATTN-CACHE] rank=0 | f16 fwd build_plans | calls=1 | time= 327.083 ms/call\n", |
| 365 | + "[FUSED-ATTN-CACHE] rank=0 | f16 bwd validate | calls=1 | time= 0.009 ms/call\n", |
| 366 | + "[FUSED-ATTN-CACHE] rank=0 | f16 bwd build_operation_graph | calls=1 | time= 1.026 ms/call\n", |
| 367 | + "[FUSED-ATTN-CACHE] rank=0 | f16 bwd create_execution_plans | calls=1 | time= 2.874 ms/call\n", |
| 368 | + "[FUSED-ATTN-CACHE] rank=0 | f16 bwd check_support | calls=1 | time= 0.016 ms/call\n", |
| 369 | + "[FUSED-ATTN-CACHE] rank=0 | f16 bwd build_plans | calls=1 | time= 514.599 ms/call\n", |
| 370 | + "[FUSED-ATTN-CACHE] rank=0 | ===== summary end =====\n", |
| 371 | + "```" |
| 372 | + ] |
| 373 | + }, |
333 | 374 | { |
334 | 375 | "cell_type": "markdown", |
335 | 376 | "id": "611d8fdb", |
|
346 | 387 | "NVTE_FUSED_ATTN = 0 # disables cuDNN attention; default = 1\n", |
347 | 388 | "```\n", |
348 | 389 | "\n", |
349 | | - "**cuDNN attention sub-backends:**\n", |
350 | | - "This environment variable allows users to express their preference of cuDNN attention sub-backends. However, the elected sub-backend will only be used *if* it is eligible, i.e. if it has support for the provided inputs and runtime environment.\n", |
351 | | - "```\n", |
352 | | - "NVTE_FUSED_ATTN_BACKEND = 1/2 # user preference of cuDNN sub-backend\n", |
353 | | - "```\n", |
354 | | - "\n", |
355 | | - "```\n", |
356 | | - "<div class=\"alert alert-info\">\n", |
357 | | - "<b>Note</b>\n", |
358 | | - " \n", |
359 | | - "Environment variables <code>NVTE_FLASH_ATTN</code>, <code>NVTE_UNFUSED_ATTN</code>, <code>NVTE_FUSED_ATTN_BACKEND</code>, and <code>NVTE_FUSED_ATTN_USE_FAv2_BWD</code> are supported in PyTorch. <code>NVTE_FUSED_ATTN</code> and <code>NVTE_ALLOW_NONDETERMINISTIC_ALGO</code> are supported in both PyTorch and JAX.\n", |
360 | | - "</div>\n", |
| 390 | + "Environment variables <code>NVTE_FLASH_ATTN</code>, <code>NVTE_UNFUSED_ATTN</code>, and <code>NVTE_FUSED_ATTN_USE_FAv2_BWD</code> are supported in PyTorch. <code>NVTE_FUSED_ATTN</code> and <code>NVTE_ALLOW_NONDETERMINISTIC_ALGO</code> are supported in both PyTorch and JAX.\n", |
361 | 391 | "\n", |
362 | 392 | "### 2.3 Example Tests\n", |
363 | 393 | "\n", |
|
0 commit comments