torch-tweak 0.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- torch_tweak-0.4.1/.claude/skills/torch-tweak-assistant/SKILL.md +159 -0
- torch_tweak-0.4.1/.cursor/rules/local-env.mdc +89 -0
- torch_tweak-0.4.1/.cursor/rules/unit-tests.mdc +270 -0
- torch_tweak-0.4.1/.dockerignore +21 -0
- torch_tweak-0.4.1/.editorconfig +23 -0
- torch_tweak-0.4.1/.github/.semgrepconfig.yml +5 -0
- torch_tweak-0.4.1/.github/CODEOWNERS +2 -0
- torch_tweak-0.4.1/.github/dependabot.yml +44 -0
- torch_tweak-0.4.1/.github/scripts/check_dist_licenses.py +102 -0
- torch_tweak-0.4.1/.github/scripts/check_installed_package.py +75 -0
- torch_tweak-0.4.1/.github/scripts/check_licenses.py +861 -0
- torch_tweak-0.4.1/.github/scripts/get_system_info.sh +104 -0
- torch_tweak-0.4.1/.github/workflows/codeql.yml +33 -0
- torch_tweak-0.4.1/.github/workflows/docs.yml +95 -0
- torch_tweak-0.4.1/.github/workflows/license-check.yml +54 -0
- torch_tweak-0.4.1/.github/workflows/lint.yml +59 -0
- torch_tweak-0.4.1/.github/workflows/nightly.yml +170 -0
- torch_tweak-0.4.1/.github/workflows/packaging.yml +89 -0
- torch_tweak-0.4.1/.github/workflows/release.yml +125 -0
- torch_tweak-0.4.1/.github/workflows/scorecard.yml +52 -0
- torch_tweak-0.4.1/.github/workflows/semgrep.yml +23 -0
- torch_tweak-0.4.1/.github/workflows/tests.yml +144 -0
- torch_tweak-0.4.1/.github/workflows/verify-release.yml +181 -0
- torch_tweak-0.4.1/.gitignore +361 -0
- torch_tweak-0.4.1/.pre-commit-config.yaml +76 -0
- torch_tweak-0.4.1/CITATION.cff +11 -0
- torch_tweak-0.4.1/CODE_OF_CONDUCT.md +73 -0
- torch_tweak-0.4.1/COMMIT_CONVENTION.md +101 -0
- torch_tweak-0.4.1/CONTRIBUTING.md +264 -0
- torch_tweak-0.4.1/ChangeLog.md +48 -0
- torch_tweak-0.4.1/LICENSE +174 -0
- torch_tweak-0.4.1/PKG-INFO +209 -0
- torch_tweak-0.4.1/README.md +125 -0
- torch_tweak-0.4.1/RELEASE_STEPS.md +80 -0
- torch_tweak-0.4.1/SECURITY.md +18 -0
- torch_tweak-0.4.1/conftest.py +70 -0
- torch_tweak-0.4.1/docs/api/backends/openvino_backend.md +20 -0
- torch_tweak-0.4.1/docs/api/backends/torch_eager_backend.md +20 -0
- torch_tweak-0.4.1/docs/api/backends/torch_inductor_backend.md +22 -0
- torch_tweak-0.4.1/docs/api/backends/torchao_backend.md +22 -0
- torch_tweak-0.4.1/docs/api/backends/xpu_graph_backend.md +20 -0
- torch_tweak-0.4.1/docs/api/tune_strategies/first_wins_strategy.md +13 -0
- torch_tweak-0.4.1/docs/api/tune_strategies/highest_throughput_strategy.md +13 -0
- torch_tweak-0.4.1/docs/api/tune_strategies/one_backend_strategy.md +13 -0
- torch_tweak-0.4.1/docs/api/tuning/backend.md +25 -0
- torch_tweak-0.4.1/docs/api/tuning/config.md +26 -0
- torch_tweak-0.4.1/docs/api/tuning/inspect.md +30 -0
- torch_tweak-0.4.1/docs/api/tuning/module.md +15 -0
- torch_tweak-0.4.1/docs/api/tuning/tuning.md +29 -0
- torch_tweak-0.4.1/docs/assets/styles.css +7 -0
- torch_tweak-0.4.1/docs/guides/advanced/execution_graphs.md +909 -0
- torch_tweak-0.4.1/docs/guides/advanced/tuning_workflow.md +461 -0
- torch_tweak-0.4.1/docs/guides/backends/openvino_backend.md +46 -0
- torch_tweak-0.4.1/docs/guides/backends/torch_eager_backend.md +53 -0
- torch_tweak-0.4.1/docs/guides/backends/torch_inductor_backend.md +202 -0
- torch_tweak-0.4.1/docs/guides/backends/torchao_backend.md +120 -0
- torch_tweak-0.4.1/docs/guides/backends/xpu_graph_backend.md +37 -0
- torch_tweak-0.4.1/docs/guides/deployment/deployment.md +124 -0
- torch_tweak-0.4.1/docs/guides/inspect.md +244 -0
- torch_tweak-0.4.1/docs/guides/tune_strategies/tune_strategies.md +211 -0
- torch_tweak-0.4.1/docs/guides/tuning.md +283 -0
- torch_tweak-0.4.1/docs/known_issues.md +16 -0
- torch_tweak-0.4.1/docs/learn/backends.md +82 -0
- torch_tweak-0.4.1/docs/learn/core_functionalities.md +148 -0
- torch_tweak-0.4.1/docs/learn/install.md +80 -0
- torch_tweak-0.4.1/docs/learn/observability.md +73 -0
- torch_tweak-0.4.1/docs/learn/overview.md +39 -0
- torch_tweak-0.4.1/docs/learn/quick_start.md +119 -0
- torch_tweak-0.4.1/docs/overrides/partials/copyright.html +8 -0
- torch_tweak-0.4.1/examples/E5Large/LICENSE +1 -0
- torch_tweak-0.4.1/examples/E5Large/README.md +72 -0
- torch_tweak-0.4.1/examples/E5Large/config.yaml +10 -0
- torch_tweak-0.4.1/examples/E5Large/e5large/__init__.py +2 -0
- torch_tweak-0.4.1/examples/E5Large/e5large/cmd_args.py +35 -0
- torch_tweak-0.4.1/examples/E5Large/e5large/inference.py +65 -0
- torch_tweak-0.4.1/examples/E5Large/e5large/model.py +25 -0
- torch_tweak-0.4.1/examples/E5Large/e5large/tune.py +124 -0
- torch_tweak-0.4.1/examples/E5Large/pyproject.toml +74 -0
- torch_tweak-0.4.1/examples/E5Large/third-party-programs.txt +1 -0
- torch_tweak-0.4.1/examples/E5Large/uv.lock +1761 -0
- torch_tweak-0.4.1/examples/ESM2/LICENSE +1 -0
- torch_tweak-0.4.1/examples/ESM2/README.md +72 -0
- torch_tweak-0.4.1/examples/ESM2/config.yaml +13 -0
- torch_tweak-0.4.1/examples/ESM2/esm2/__init__.py +3 -0
- torch_tweak-0.4.1/examples/ESM2/esm2/infer.py +74 -0
- torch_tweak-0.4.1/examples/ESM2/esm2/tune.py +85 -0
- torch_tweak-0.4.1/examples/ESM2/pyproject.toml +59 -0
- torch_tweak-0.4.1/examples/ESM2/third-party-programs.txt +1 -0
- torch_tweak-0.4.1/examples/ESM2/uv.lock +1573 -0
- torch_tweak-0.4.1/examples/FLUX/LICENSE +1 -0
- torch_tweak-0.4.1/examples/FLUX/README.md +70 -0
- torch_tweak-0.4.1/examples/FLUX/flux/__init__.py +3 -0
- torch_tweak-0.4.1/examples/FLUX/flux/cmd_args.py +98 -0
- torch_tweak-0.4.1/examples/FLUX/flux/inference.py +103 -0
- torch_tweak-0.4.1/examples/FLUX/flux/model.py +23 -0
- torch_tweak-0.4.1/examples/FLUX/flux/tune.py +117 -0
- torch_tweak-0.4.1/examples/FLUX/pyproject.toml +60 -0
- torch_tweak-0.4.1/examples/FLUX/third-party-programs.txt +1 -0
- torch_tweak-0.4.1/examples/FLUX/uv.lock +1853 -0
- torch_tweak-0.4.1/examples/LLM/LICENSE +1 -0
- torch_tweak-0.4.1/examples/LLM/README.md +206 -0
- torch_tweak-0.4.1/examples/LLM/llm/__init__.py +6 -0
- torch_tweak-0.4.1/examples/LLM/llm/benchmark.py +215 -0
- torch_tweak-0.4.1/examples/LLM/llm/benchmark_all.py +54 -0
- torch_tweak-0.4.1/examples/LLM/llm/cmd_args.py +126 -0
- torch_tweak-0.4.1/examples/LLM/llm/tune.py +137 -0
- torch_tweak-0.4.1/examples/LLM/pyproject.toml +60 -0
- torch_tweak-0.4.1/examples/LLM/third-party-programs.txt +1 -0
- torch_tweak-0.4.1/examples/LLM/uv.lock +1614 -0
- torch_tweak-0.4.1/examples/Minimal/LICENSE +1 -0
- torch_tweak-0.4.1/examples/Minimal/README.md +25 -0
- torch_tweak-0.4.1/examples/Minimal/demo.py +52 -0
- torch_tweak-0.4.1/examples/Minimal/pyproject.toml +50 -0
- torch_tweak-0.4.1/examples/Minimal/third-party-programs.txt +1 -0
- torch_tweak-0.4.1/examples/Minimal/uv.lock +1002 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/LICENSE +1 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/README.md +76 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/config.yaml +6 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/parakeet_ctc/__init__.py +9 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/parakeet_ctc/_dependency_patches.py +113 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/parakeet_ctc/cmd_args.py +39 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/parakeet_ctc/inference.py +68 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/parakeet_ctc/model.py +79 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/parakeet_ctc/patch_nv_one_logger.py +14 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/parakeet_ctc/sample_data.py +38 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/parakeet_ctc/tune.py +103 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/pyproject.toml +67 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/third-party-programs.txt +1 -0
- torch_tweak-0.4.1/examples/ParakeetCTC/uv.lock +5421 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/LICENSE +1 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/README.md +92 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/config.yaml +6 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/parakeet_rnnt/__init__.py +9 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/parakeet_rnnt/_dependency_patches.py +113 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/parakeet_rnnt/benchmark.py +114 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/parakeet_rnnt/cmd_args.py +43 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/parakeet_rnnt/inference.py +58 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/parakeet_rnnt/model.py +84 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/parakeet_rnnt/patch_nv_one_logger.py +14 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/parakeet_rnnt/sample_data.py +38 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/parakeet_rnnt/tune.py +117 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/pyproject.toml +68 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/third-party-programs.txt +1 -0
- torch_tweak-0.4.1/examples/ParakeetRNNT/uv.lock +5421 -0
- torch_tweak-0.4.1/examples/README.md +165 -0
- torch_tweak-0.4.1/examples/ResNet/LICENSE +1 -0
- torch_tweak-0.4.1/examples/ResNet/README.md +64 -0
- torch_tweak-0.4.1/examples/ResNet/dog.webp +0 -0
- torch_tweak-0.4.1/examples/ResNet/imagenet_classes.txt +1000 -0
- torch_tweak-0.4.1/examples/ResNet/pyproject.toml +57 -0
- torch_tweak-0.4.1/examples/ResNet/resnet/__init__.py +6 -0
- torch_tweak-0.4.1/examples/ResNet/resnet/cmd_args.py +41 -0
- torch_tweak-0.4.1/examples/ResNet/resnet/inference.py +73 -0
- torch_tweak-0.4.1/examples/ResNet/resnet/model.py +22 -0
- torch_tweak-0.4.1/examples/ResNet/resnet/tune.py +93 -0
- torch_tweak-0.4.1/examples/ResNet/third-party-programs.txt +1 -0
- torch_tweak-0.4.1/examples/ResNet/uv.lock +1369 -0
- torch_tweak-0.4.1/examples/StableDiffusion/.gitignore +1 -0
- torch_tweak-0.4.1/examples/StableDiffusion/LICENSE +1 -0
- torch_tweak-0.4.1/examples/StableDiffusion/README.md +92 -0
- torch_tweak-0.4.1/examples/StableDiffusion/pyproject.toml +82 -0
- torch_tweak-0.4.1/examples/StableDiffusion/stable_diffusion/__init__.py +3 -0
- torch_tweak-0.4.1/examples/StableDiffusion/stable_diffusion/benchmark_hybrid.py +245 -0
- torch_tweak-0.4.1/examples/StableDiffusion/stable_diffusion/cmd_args.py +90 -0
- torch_tweak-0.4.1/examples/StableDiffusion/stable_diffusion/inference.py +50 -0
- torch_tweak-0.4.1/examples/StableDiffusion/stable_diffusion/model.py +31 -0
- torch_tweak-0.4.1/examples/StableDiffusion/stable_diffusion/tune.py +50 -0
- torch_tweak-0.4.1/examples/StableDiffusion/stable_diffusion/tuning_strategy.py +58 -0
- torch_tweak-0.4.1/examples/StableDiffusion/third-party-programs.txt +1 -0
- torch_tweak-0.4.1/examples/StableDiffusion/uv.lock +2329 -0
- torch_tweak-0.4.1/notebooks/README.md +36 -0
- torch_tweak-0.4.1/notebooks/inspect_module_demo.ipynb +235 -0
- torch_tweak-0.4.1/notebooks/sample_metadata_walkthrough.ipynb +787 -0
- torch_tweak-0.4.1/notebooks/saving_loading_checkpoints.ipynb +744 -0
- torch_tweak-0.4.1/notebooks/storage.ipynb +368 -0
- torch_tweak-0.4.1/notebooks/wrapper_module_demo.ipynb +538 -0
- torch_tweak-0.4.1/properdocs.yml +132 -0
- torch_tweak-0.4.1/pyproject.toml +215 -0
- torch_tweak-0.4.1/scripts/stage_docs.py +37 -0
- torch_tweak-0.4.1/tests/__init__.py +2 -0
- torch_tweak-0.4.1/tests/fixtures/synthetic_prompts_100.json +402 -0
- torch_tweak-0.4.1/tests/functional/dataloader/test_huggingface_gpt2_tokenizer.py +53 -0
- torch_tweak-0.4.1/tests/functional/dataloader/test_resnet.py +60 -0
- torch_tweak-0.4.1/tests/functional/dataloader/test_transformers_distilbert.py +48 -0
- torch_tweak-0.4.1/tests/functional/dataloader/test_transformers_t5_tokenizer.py +45 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_dynamo_export_optional_kwargs.py +110 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_inspect_module_flux.py +55 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_inspect_module_resnet.py +38 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_inspect_module_stable_diffusion.py +60 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_resnet_openvino_backend.py +47 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_tune_llm.py +150 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_tune_resnet_torch_compile_backend.py +47 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_tune_resnet_torch_eager_backend.py +83 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_tune_resnet_torchao_backend.py +74 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_tune_resnet_with_forward_hooks.py +56 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_tune_resnet_with_module_device.py +56 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_tune_save_load.py +111 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_tune_save_load_first_module_only.py +90 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_version.py +21 -0
- torch_tweak-0.4.1/tests/functional/pytorch/test_torch_tweak_wrap_module_resnet.py +45 -0
- torch_tweak-0.4.1/tests/toy_backends.py +72 -0
- torch_tweak-0.4.1/tests/toy_models/__init__.py +9 -0
- torch_tweak-0.4.1/tests/toy_models/torch_models.py +186 -0
- torch_tweak-0.4.1/tests/unit/__init__.py +2 -0
- torch_tweak-0.4.1/tests/unit/torch/__init__.py +2 -0
- torch_tweak-0.4.1/tests/unit/torch/backend/__init__.py +2 -0
- torch_tweak-0.4.1/tests/unit/torch/backend/test_backend.py +364 -0
- torch_tweak-0.4.1/tests/unit/torch/backend/test_backend_build_is_idempotent.py +60 -0
- torch_tweak-0.4.1/tests/unit/torch/backend/test_openvino_backend.py +593 -0
- torch_tweak-0.4.1/tests/unit/torch/backend/test_torch_eager_backend.py +124 -0
- torch_tweak-0.4.1/tests/unit/torch/backend/test_torch_inductor_backend.py +173 -0
- torch_tweak-0.4.1/tests/unit/torch/backend/test_torchao_backend.py +250 -0
- torch_tweak-0.4.1/tests/unit/torch/backend/test_xpu_graph_backend.py +340 -0
- torch_tweak-0.4.1/tests/unit/torch/checkpoint/__init__.py +2 -0
- torch_tweak-0.4.1/tests/unit/torch/checkpoint/test_local_torch_storage.py +66 -0
- torch_tweak-0.4.1/tests/unit/torch/checkpoint/test_storage_tasks.py +572 -0
- torch_tweak-0.4.1/tests/unit/torch/checkpoint/test_torch_checkpoint.py +446 -0
- torch_tweak-0.4.1/tests/unit/torch/inspecting/test_inspecting.py +421 -0
- torch_tweak-0.4.1/tests/unit/torch/inspecting/test_module_info.py +99 -0
- torch_tweak-0.4.1/tests/unit/torch/inspecting/test_module_inspector.py +785 -0
- torch_tweak-0.4.1/tests/unit/torch/inspecting/test_wrapping.py +462 -0
- torch_tweak-0.4.1/tests/unit/torch/module/__init__.py +2 -0
- torch_tweak-0.4.1/tests/unit/torch/module/test_graph_spec.py +76 -0
- torch_tweak-0.4.1/tests/unit/torch/module/test_locator.py +476 -0
- torch_tweak-0.4.1/tests/unit/torch/module/test_passthrough_module.py +35 -0
- torch_tweak-0.4.1/tests/unit/torch/module/test_recording_module.py +147 -0
- torch_tweak-0.4.1/tests/unit/torch/module/test_sample_metadata.py +483 -0
- torch_tweak-0.4.1/tests/unit/torch/module/test_tensor_spec.py +235 -0
- torch_tweak-0.4.1/tests/unit/torch/module/test_tuned_module.py +86 -0
- torch_tweak-0.4.1/tests/unit/torch/module/test_wrapper_module.py +415 -0
- torch_tweak-0.4.1/tests/unit/torch/task/__init__.py +2 -0
- torch_tweak-0.4.1/tests/unit/torch/task/test_correctness.py +151 -0
- torch_tweak-0.4.1/tests/unit/torch/task/test_find_max_batch_size.py +79 -0
- torch_tweak-0.4.1/tests/unit/torch/task/test_profiling.py +262 -0
- torch_tweak-0.4.1/tests/unit/torch/test_dataloader.py +462 -0
- torch_tweak-0.4.1/tests/unit/torch/test_global_context.py +74 -0
- torch_tweak-0.4.1/tests/unit/torch/test_torch_llm_support.py +285 -0
- torch_tweak-0.4.1/tests/unit/torch/test_tuning.py +202 -0
- torch_tweak-0.4.1/tests/unit/torch/tune_strategy/__init__.py +2 -0
- torch_tweak-0.4.1/tests/unit/torch/tune_strategy/test_correctness_extension.py +119 -0
- torch_tweak-0.4.1/tests/unit/torch/tune_strategy/test_first_wins_strategy.py +211 -0
- torch_tweak-0.4.1/tests/unit/torch/tune_strategy/test_highest_throughput_strategy.py +261 -0
- torch_tweak-0.4.1/tests/unit/torch/tune_strategy/test_one_backend_strategy.py +89 -0
- torch_tweak-0.4.1/tests/unit/torch/utils/__init__.py +2 -0
- torch_tweak-0.4.1/tests/unit/torch/utils/test_device.py +175 -0
- torch_tweak-0.4.1/tests/unit/torch/utils/test_graph_break_detector.py +76 -0
- torch_tweak-0.4.1/tests/unit/torch/utils/test_module_utils.py +188 -0
- torch_tweak-0.4.1/tests/unit/torch/utils/test_path_utils.py +33 -0
- torch_tweak-0.4.1/tests/unit/torch/utils/test_xpu.py +42 -0
- torch_tweak-0.4.1/tests/unit/utils/__init__.py +2 -0
- torch_tweak-0.4.1/tests/unit/utils/test_timer.py +566 -0
- torch_tweak-0.4.1/tests/utilities/__init__.py +3 -0
- torch_tweak-0.4.1/tests/utilities/helpers.py +54 -0
- torch_tweak-0.4.1/tests/utilities/prompts.py +9 -0
- torch_tweak-0.4.1/third-party-programs.txt +198 -0
- torch_tweak-0.4.1/torch_tweak/__init__.py +9 -0
- torch_tweak-0.4.1/torch_tweak/__version__.py +11 -0
- torch_tweak-0.4.1/torch_tweak/global_context.py +73 -0
- torch_tweak-0.4.1/torch_tweak/torch/__init__.py +40 -0
- torch_tweak-0.4.1/torch_tweak/torch/backend/__init__.py +27 -0
- torch_tweak-0.4.1/torch_tweak/torch/backend/backend.py +477 -0
- torch_tweak-0.4.1/torch_tweak/torch/backend/openvino/__init__.py +8 -0
- torch_tweak-0.4.1/torch_tweak/torch/backend/openvino/openvino_backend.py +269 -0
- torch_tweak-0.4.1/torch_tweak/torch/backend/openvino/ov_model_converter.py +425 -0
- torch_tweak-0.4.1/torch_tweak/torch/backend/torch_eager.py +165 -0
- torch_tweak-0.4.1/torch_tweak/torch/backend/torch_inductor_backend.py +266 -0
- torch_tweak-0.4.1/torch_tweak/torch/backend/torchao_backend.py +340 -0
- torch_tweak-0.4.1/torch_tweak/torch/backend/xpu_graph_backend.py +326 -0
- torch_tweak-0.4.1/torch_tweak/torch/checkpoint/__init__.py +3 -0
- torch_tweak-0.4.1/torch_tweak/torch/checkpoint/checkpoint.py +55 -0
- torch_tweak-0.4.1/torch_tweak/torch/checkpoint/local_torch_storage.py +67 -0
- torch_tweak-0.4.1/torch_tweak/torch/checkpoint/storage.py +67 -0
- torch_tweak-0.4.1/torch_tweak/torch/checkpoint/storage_tasks.py +528 -0
- torch_tweak-0.4.1/torch_tweak/torch/checkpoint/torch_checkpoint.py +336 -0
- torch_tweak-0.4.1/torch_tweak/torch/config.py +104 -0
- torch_tweak-0.4.1/torch_tweak/torch/dataloader.py +555 -0
- torch_tweak-0.4.1/torch_tweak/torch/inspecting/__init__.py +11 -0
- torch_tweak-0.4.1/torch_tweak/torch/inspecting/inspecting.py +123 -0
- torch_tweak-0.4.1/torch_tweak/torch/inspecting/module_info.py +188 -0
- torch_tweak-0.4.1/torch_tweak/torch/inspecting/module_inspector.py +428 -0
- torch_tweak-0.4.1/torch_tweak/torch/inspecting/wrapping.py +49 -0
- torch_tweak-0.4.1/torch_tweak/torch/integrations/__init__.py +3 -0
- torch_tweak-0.4.1/torch_tweak/torch/integrations/hugging_face.py +20 -0
- torch_tweak-0.4.1/torch_tweak/torch/module/__init__.py +9 -0
- torch_tweak-0.4.1/torch_tweak/torch/module/graph_spec.py +85 -0
- torch_tweak-0.4.1/torch_tweak/torch/module/locator.py +435 -0
- torch_tweak-0.4.1/torch_tweak/torch/module/passthrough_module.py +44 -0
- torch_tweak-0.4.1/torch_tweak/torch/module/recording_module.py +159 -0
- torch_tweak-0.4.1/torch_tweak/torch/module/sample_metadata.py +466 -0
- torch_tweak-0.4.1/torch_tweak/torch/module/tensor_spec.py +271 -0
- torch_tweak-0.4.1/torch_tweak/torch/module/tuned_module.py +142 -0
- torch_tweak-0.4.1/torch_tweak/torch/module/wrapper_module.py +483 -0
- torch_tweak-0.4.1/torch_tweak/torch/module_registry.py +48 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/__init__.py +29 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/correctness.py +85 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/find_max_batch_size.py +133 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/profiling/__init__.py +38 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/profiling/config.py +57 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/profiling/events.py +33 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/profiling/measuring_stop_strategy.py +82 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/profiling/measuring_strategy.py +70 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/profiling/metrics.py +77 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/profiling/profiling.py +193 -0
- torch_tweak-0.4.1/torch_tweak/torch/task/profiling/profiling_stop_strategy.py +77 -0
- torch_tweak-0.4.1/torch_tweak/torch/tune_strategy/__init__.py +12 -0
- torch_tweak-0.4.1/torch_tweak/torch/tune_strategy/extension/__init__.py +18 -0
- torch_tweak-0.4.1/torch_tweak/torch/tune_strategy/extension/find_max_batch_size_extension.py +175 -0
- torch_tweak-0.4.1/torch_tweak/torch/tune_strategy/first_wins_strategy.py +105 -0
- torch_tweak-0.4.1/torch_tweak/torch/tune_strategy/highest_throughput_strategy.py +236 -0
- torch_tweak-0.4.1/torch_tweak/torch/tune_strategy/one_backend_strategy.py +73 -0
- torch_tweak-0.4.1/torch_tweak/torch/tune_strategy/tune_strategy.py +242 -0
- torch_tweak-0.4.1/torch_tweak/torch/tuning.py +221 -0
- torch_tweak-0.4.1/torch_tweak/torch/utils/__init__.py +3 -0
- torch_tweak-0.4.1/torch_tweak/torch/utils/device.py +48 -0
- torch_tweak-0.4.1/torch_tweak/torch/utils/graph_break_detector.py +50 -0
- torch_tweak-0.4.1/torch_tweak/torch/utils/memory.py +45 -0
- torch_tweak-0.4.1/torch_tweak/torch/utils/module.py +175 -0
- torch_tweak-0.4.1/torch_tweak/torch/utils/path_utils.py +77 -0
- torch_tweak-0.4.1/torch_tweak/torch/utils/xpu.py +79 -0
- torch_tweak-0.4.1/torch_tweak/utils/__init__.py +19 -0
- torch_tweak-0.4.1/torch_tweak/utils/hashing.py +12 -0
- torch_tweak-0.4.1/torch_tweak/utils/logging.py +471 -0
- torch_tweak-0.4.1/torch_tweak/utils/permissions.py +34 -0
- torch_tweak-0.4.1/torch_tweak/utils/system_monitor.py +391 -0
- torch_tweak-0.4.1/torch_tweak/utils/timer.py +320 -0
- torch_tweak-0.4.1/torch_tweak/utils/trace.py +61 -0
- torch_tweak-0.4.1/uv.lock +2153 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
3
|
+
Copyright (c) 2026 Intel Corporation
|
|
4
|
+
SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
NOTE: This file has been modified by Intel Corporation.
|
|
6
|
+
-->
|
|
7
|
+
---
|
|
8
|
+
name: torch-tweak-assistant
|
|
9
|
+
description: Provides expert guidance on Torch Tweak workflows, tuning strategies, backends, and best practices. Use when working with model tuning, inference optimization, or PyTorch model deployment.
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Torch Tweak Assistant Skill
|
|
13
|
+
|
|
14
|
+
You are an expert assistant for Torch Tweak, an inference toolkit for tuning and deploying Deep Learning models on Intel GPUs / XPU's.
|
|
15
|
+
|
|
16
|
+
This skill provides structured, decision-oriented guidance for tuning, backends, and strategies, and for diagnosing performance or compilation issues.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
# Skill Activation Criteria
|
|
21
|
+
|
|
22
|
+
Activate this skill when:
|
|
23
|
+
|
|
24
|
+
- The user mentions **Torch Tweak**
|
|
25
|
+
- The user asks about inference optimization on Intel GPUs / XPU's
|
|
26
|
+
- The user references Torch, OpenVINO, TorchAO, or Torch Inductor in a performance context
|
|
27
|
+
- The user wants to improve PyTorch model inference performance
|
|
28
|
+
- The user is deploying to production with Intel GPUs / XPU's
|
|
29
|
+
|
|
30
|
+
Do NOT activate this skill when:
|
|
31
|
+
|
|
32
|
+
- The question is about model training
|
|
33
|
+
- The topic is general PyTorch usage unrelated to inference optimization
|
|
34
|
+
- The topic is unrelated to Intel GPU / XPU inference workflows
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
# Core Concepts
|
|
39
|
+
|
|
40
|
+
## Torch Tweak Overview
|
|
41
|
+
|
|
42
|
+
- **Purpose**: Tune PyTorch models and pipelines for optimal inference performance
|
|
43
|
+
- **Key Feature**: Single Python API supporting TorchAO, Torch Inductor, eager, and OpenVINO
|
|
44
|
+
- **Use Cases**: Computer Vision, Large Language Models (LLMs), Natural Language Processing, Speech Recognition, Generative AI (Stable Diffusion, FLUX)
|
|
45
|
+
- **Examples**: See `examples/` directory for Minimal, LLM, ResNet, StableDiffusion, FLUX, Parakeet, ESM2, E5Large
|
|
46
|
+
|
|
47
|
+
### Tuning
|
|
48
|
+
|
|
49
|
+
- Requires a small amount of integration in the Python pipeline
|
|
50
|
+
- Full control over the tuning process
|
|
51
|
+
- Supports batch detection, dynamic axes, and benchmarking
|
|
52
|
+
- Can save and load tuned models
|
|
53
|
+
- Supports caching
|
|
54
|
+
|
|
55
|
+
## Common Workflows
|
|
56
|
+
|
|
57
|
+
### Tuning workflow
|
|
58
|
+
1. **Inspect**: Use `tt.inspect(model, input_data)` to analyze model structure
|
|
59
|
+
2. **Wrap**: Use `tt.wrap(model, modules)` to prepare modules for tuning
|
|
60
|
+
3. **Tune**: Use `tt.tune(model, input_data)` to optimize
|
|
61
|
+
4. **Save**: Use `tt.save(model, "path.tt")` to persist tuned models
|
|
62
|
+
5. **Load**: Use `tt.load(model, "path.tt")` to load saved models
|
|
63
|
+
|
|
64
|
+
## Backends
|
|
65
|
+
|
|
66
|
+
### TorchAO Backend
|
|
67
|
+
- **Best for**: PyTorch-native quantization on Intel GPU / XPU
|
|
68
|
+
|
|
69
|
+
### Torch Inductor Backend
|
|
70
|
+
- **Best for**: PyTorch compiler-based optimization on Intel GPU / XPU
|
|
71
|
+
|
|
72
|
+
### XPU Graph Backend
|
|
73
|
+
- **Best for**: replaying a module that was recorded once during tuning
|
|
74
|
+
- **Rejection**: failed, empty, or incorrect recordings are dropped for that module and input
|
|
75
|
+
|
|
76
|
+
### OpenVINO Backend
|
|
77
|
+
- **Best for**: an OpenVINO model on an Intel CPU or GPU
|
|
78
|
+
- **Strengths**:
|
|
79
|
+
- Converts PyTorch models to OpenVINO IR for deployment
|
|
80
|
+
- Applies hardware-specific optimizations
|
|
81
|
+
- Supports both CPU and GPU execution
|
|
82
|
+
- Supports OpenVINO performance hints for latency- or throughput-oriented compilation
|
|
83
|
+
|
|
84
|
+
### Torch Eager Backend
|
|
85
|
+
- **Best for**: the uncompiled baseline inside a throughput search
|
|
86
|
+
|
|
87
|
+
## Tuning Strategies
|
|
88
|
+
|
|
89
|
+
1. **FirstWinsStrategy**: Selects first successful backend
|
|
90
|
+
2. **OneBackendStrategy**: Uses only specified backend
|
|
91
|
+
3. **HighestThroughputStrategy**: Selects backend with best throughput
|
|
92
|
+
|
|
93
|
+
## Best Practices
|
|
94
|
+
|
|
95
|
+
### Backend Selection
|
|
96
|
+
- **HighestThroughputStrategy**: the default list is Torch Inductor, XPU graph, and eager. It measures each one and keeps the fastest. List order does not change the winner. TorchAO and OpenVINO are optional additions.
|
|
97
|
+
- **FirstWinsStrategy**: default order is XPU graph, Torch Inductor, OpenVINO, then eager. The first backend that builds is kept. TorchAO is not in that default, because the first backend that builds wins and a quantization that builds would be kept without a speed comparison.
|
|
98
|
+
|
|
99
|
+
### Common Issues
|
|
100
|
+
- **Graph breaks**: conditional logic in a module blocks tuning of that module
|
|
101
|
+
|
|
102
|
+
## Code Patterns
|
|
103
|
+
|
|
104
|
+
### Basic Tuning
|
|
105
|
+
```python
|
|
106
|
+
import torch_tweak.torch as tt
|
|
107
|
+
|
|
108
|
+
# Inspect
|
|
109
|
+
modules_info = tt.inspect(model, input_data)
|
|
110
|
+
modules_info.describe()
|
|
111
|
+
|
|
112
|
+
# Wrap and tune
|
|
113
|
+
modules = modules_info.get_modules()
|
|
114
|
+
model = tt.wrap(model, modules)
|
|
115
|
+
tt.tune(model, input_data)
|
|
116
|
+
|
|
117
|
+
# Save/load
|
|
118
|
+
tt.save(model, "tuned_model.tt")
|
|
119
|
+
tt.load(model, "tuned_model.tt")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Backend Configuration
|
|
123
|
+
```python
|
|
124
|
+
from torch_tweak.torch.backend import (
|
|
125
|
+
TorchAOBackend,
|
|
126
|
+
TorchInductorBackend,
|
|
127
|
+
XPUGraphBackend,
|
|
128
|
+
OpenVINOBackend,
|
|
129
|
+
TorchEagerBackend,
|
|
130
|
+
)
|
|
131
|
+
from torch_tweak.torch.tune_strategy import HighestThroughputStrategy
|
|
132
|
+
|
|
133
|
+
strategy = HighestThroughputStrategy(
|
|
134
|
+
backends=[
|
|
135
|
+
TorchAOBackend(),
|
|
136
|
+
TorchInductorBackend(),
|
|
137
|
+
XPUGraphBackend(),
|
|
138
|
+
OpenVINOBackend(),
|
|
139
|
+
TorchEagerBackend(),
|
|
140
|
+
]
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## When Helping Users
|
|
145
|
+
|
|
146
|
+
1. **Recommend backends**: Based on performance needs and constraints
|
|
147
|
+
2. **Explain trade-offs**: Performance vs ease-of-use, control vs automation
|
|
148
|
+
3. **Provide code examples**: Show complete workflows, not just snippets
|
|
149
|
+
4. **Address common pitfalls**: Graph breaks
|
|
150
|
+
5. Don't commit a non-standard ascii characters in the code, especially in the comments (unless specifically specified by the user). Example: avoid dashes, use simple hyphens.
|
|
151
|
+
|
|
152
|
+
## Key Files to Reference
|
|
153
|
+
|
|
154
|
+
- `torch_tweak/torch/` - Tuning API
|
|
155
|
+
- `torch_tweak/torch/backend/` - Backend implementations
|
|
156
|
+
- `torch_tweak/torch/tune_strategy/` - Tuning strategies
|
|
157
|
+
- Examples in `examples/` directory
|
|
158
|
+
|
|
159
|
+
Always provide context-aware guidance based on the user's specific needs and the codebase structure.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Local build, run, and test Torch Tweak with uv (stable or nightly XPU)
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Torch Tweak - local environment (uv)
|
|
7
|
+
|
|
8
|
+
## Scope
|
|
9
|
+
|
|
10
|
+
Use this workflow for **local** installs, demos, and tests.
|
|
11
|
+
|
|
12
|
+
- **Default Python stack:** uv + **stable** PyTorch XPU - venv **`.venv`** (`default-groups = ["xpu-stable"]`).
|
|
13
|
+
- **Optional:** uv + **nightly** PyTorch XPU - separate venv **`.venv-nightly`** (`xpu-nightly` group).
|
|
14
|
+
|
|
15
|
+
## uv - stable environment (default)
|
|
16
|
+
|
|
17
|
+
From the repository root. **Do not** set `UV_PROJECT_ENVIRONMENT` (uv uses **`.venv`**).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
uv sync --extra dev
|
|
21
|
+
uv run pytest
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Example:
|
|
25
|
+
```bash
|
|
26
|
+
uv sync --extra dev
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
uv run ruff check --fix && uv run ruff format
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Prefer `uv run …` over manually activating `.venv/bin/activate`.
|
|
34
|
+
|
|
35
|
+
## uv - nightly environment (optional)
|
|
36
|
+
|
|
37
|
+
Use nightly only when the task needs **PyTorch XPU nightly** wheels. Keep nightly in a **separate** venv so it does not fight stable.
|
|
38
|
+
|
|
39
|
+
| | Stable | Nightly |
|
|
40
|
+
|---|--------|---------|
|
|
41
|
+
| Venv path | `.venv` (default) | `.venv-nightly` |
|
|
42
|
+
| `UV_PROJECT_ENVIRONMENT` | unset | `.venv-nightly` |
|
|
43
|
+
| Sync | `uv sync --extra dev` | `uv sync --no-default-groups --group xpu-nightly --extra dev` |
|
|
44
|
+
| Every `uv run` | no extra env var | `UV_PROJECT_ENVIRONMENT=.venv-nightly` |
|
|
45
|
+
|
|
46
|
+
**Install / refresh nightly:**
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
UV_PROJECT_ENVIRONMENT=.venv-nightly uv sync --no-default-groups --group xpu-nightly --extra dev
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Run tests on nightly:**
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
UV_PROJECT_ENVIRONMENT=.venv-nightly uv run pytest
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Nightly rules (do not break resolution)
|
|
59
|
+
|
|
60
|
+
1. Never activate **`xpu-nightly` and `xpu-stable` in the same `uv sync`** (conflicts in `pyproject.toml`).
|
|
61
|
+
2. Nightly sync **must** include **`--no-default-groups --group xpu-nightly`** so `default-groups = ["xpu-stable"]` is not applied.
|
|
62
|
+
3. Do **not** use `uv sync --only-group xpu-nightly --extra dev` - use `--no-default-groups --group xpu-nightly --extra dev` instead.
|
|
63
|
+
4. Set **`UV_PROJECT_ENVIRONMENT=.venv-nightly`** on **both** `uv sync` and `uv run` when working in the nightly tree.
|
|
64
|
+
5. Switching nightly ↔ stable in a **single** `.venv` is possible but reinstalls `torch`; prefer two directories (`.venv` + `.venv-nightly`).
|
|
65
|
+
|
|
66
|
+
**Back to stable** (from repo root, default venv):
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
uv sync --extra dev
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Agent rules
|
|
73
|
+
|
|
74
|
+
1. When diagnosing failures, **reproduce the exact command** (stable vs nightly, `UV_PROJECT_ENVIRONMENT`, and uv flags) before changing code.
|
|
75
|
+
2. Default to **stable** (`.venv`, `uv sync --extra dev`). Use **nightly** only when the user or task explicitly requires nightly PyTorch.
|
|
76
|
+
3. If you add Python packages for a demo or test, update **`pyproject.toml`** in the same change and run **`uv lock`** + **`uv sync`** (with the correct stable or nightly flags).
|
|
77
|
+
4. Don't commit a non-standard ascii characters in the code, especially in the comments (unless specifically specified by the user). Example: avoid dashes, use simple hyphens, avoid arrows etc. Keep it simple and readable.
|
|
78
|
+
|
|
79
|
+
## Quick reference
|
|
80
|
+
|
|
81
|
+
| Task | Command |
|
|
82
|
+
|------|---------|
|
|
83
|
+
| Stable: install deps | `uv sync --extra dev` |
|
|
84
|
+
| Stable: unit tests | `uv run pytest` |
|
|
85
|
+
| Stable: OpenVINO tests | `uv run pytest tests/unit/torch/backend/test_openvino_backend.py -v` |
|
|
86
|
+
| Nightly: install deps | `UV_PROJECT_ENVIRONMENT=.venv-nightly uv sync --no-default-groups --group xpu-nightly --extra dev` |
|
|
87
|
+
| Nightly: unit tests | `UV_PROJECT_ENVIRONMENT=.venv-nightly uv run pytest` |
|
|
88
|
+
| Ruff (lint + fix) | `uv run ruff check --fix && uv run ruff format` |
|
|
89
|
+
| Pre-commit | `uv run pre-commit run --all-files` |
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: How to write unit and functional tests in Torch Tweak. Use when adding or editing tests under tests/, conftest.py, or when the user asks for a test.
|
|
3
|
+
globs: "{tests/**/*.py,conftest.py}"
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Tests
|
|
8
|
+
|
|
9
|
+
A test is one example: a known input and the output you expect.
|
|
10
|
+
Tests are untested code. A bug in a test may let a product bug ship, and nothing is watching the test.
|
|
11
|
+
Keep the test simple enough that a wrong example is obvious.
|
|
12
|
+
A test that builds the expected value with the same formula as the code stays green when both are wrong.
|
|
13
|
+
A reader names the behavior in under a minute. If they cannot, the test is wrong.
|
|
14
|
+
Apply this when you add or edit a test. Leave the rest of the file alone.
|
|
15
|
+
|
|
16
|
+
## Dumb
|
|
17
|
+
|
|
18
|
+
Write the input as a literal, write the expected output as a literal, and compare them.
|
|
19
|
+
|
|
20
|
+
Production code may build the object under test. It may supply the input.
|
|
21
|
+
It must not compute the expected value.
|
|
22
|
+
A copied formula is the same mistake. The test and the code then share one bug.
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
# Bad. from_inputs is the code under test, used as its own oracle.
|
|
26
|
+
expected = SampleMetadata.from_inputs(args=None, kwargs={"x": x}, strict=True).to_dict()
|
|
27
|
+
assert actual.to_dict() == expected
|
|
28
|
+
|
|
29
|
+
# Good. The values the test owns are written out.
|
|
30
|
+
payload = actual.to_dict()
|
|
31
|
+
assert payload["strict"] is True
|
|
32
|
+
assert payload["other_data"][0]["value"] == "hello"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Compare the field this test owns. A full expected object is right when every field is the point. Otherwise assert that field and stop.
|
|
36
|
+
|
|
37
|
+
A tuned module, a replayed graph, or a loaded checkpoint matches eager, or a literal tensor.
|
|
38
|
+
Capture eager before tune. That run is the oracle. The tuned path is the subject.
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
eager = model(sample)
|
|
42
|
+
|
|
43
|
+
tune(module, sample)
|
|
44
|
+
|
|
45
|
+
torch.testing.assert_close(module(sample), eager, rtol=1e-4, atol=1e-5)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Do not run the subject twice and compare it to itself.
|
|
49
|
+
Floats go through `torch.testing.assert_close` with `rtol` and `atol` on that call.
|
|
50
|
+
Do not walk elements. Do not branch on NaN. `assert_close` already prints the mismatch.
|
|
51
|
+
|
|
52
|
+
## No logic
|
|
53
|
+
|
|
54
|
+
A branch or a loop in a test is untested code. Every path you would demand in production is invisible here.
|
|
55
|
+
No `if`, `for`, `while`, or `try` that decides what is correct.
|
|
56
|
+
`pytest.raises` is the assertion.
|
|
57
|
+
`pytest.mark.parametrize` is a list of examples. Each row is written out. The body does not switch on the parameter.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
# Bad. The branch is a second program.
|
|
61
|
+
@pytest.mark.parametrize("kind", ["nan", "inf"])
|
|
62
|
+
def test_non_finite(kind):
|
|
63
|
+
value = float("nan") if kind == "nan" else float("inf")
|
|
64
|
+
with pytest.raises(CorrectnessValueError):
|
|
65
|
+
check_output_correctness({"logits": torch.tensor([value])})
|
|
66
|
+
|
|
67
|
+
# Good. Two examples. The message is part of the example.
|
|
68
|
+
@pytest.mark.parametrize(
|
|
69
|
+
("value", "message"),
|
|
70
|
+
[(float("nan"), "NaN"), (float("inf"), "infinity")],
|
|
71
|
+
)
|
|
72
|
+
def test_non_finite_tensor_is_rejected(value, message):
|
|
73
|
+
with pytest.raises(CorrectnessValueError, match=message):
|
|
74
|
+
check_output_correctness({"logits": torch.tensor([1.0, value])})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Catch the subclass the code raises. `pytest.raises(CorrectnessValueError)` alone is still weak. A different `CorrectnessValueError` passes. Pass `match`.
|
|
78
|
+
|
|
79
|
+
A helper may build a fixed tensor or a toy module.
|
|
80
|
+
Do not put a branch in a helper unless that helper has its own tests.
|
|
81
|
+
|
|
82
|
+
## One fact
|
|
83
|
+
|
|
84
|
+
Each test covers one behavior.
|
|
85
|
+
A second fact is a second test. One more check in a green test hides which fact broke.
|
|
86
|
+
Several asserts may describe one fact: the shape and the dtype of the same tensor.
|
|
87
|
+
|
|
88
|
+
A round trip is one behavior. Save, load, forward, then one compare.
|
|
89
|
+
An assert between the steps is a second test.
|
|
90
|
+
|
|
91
|
+
When a unit test fails, the reader should already know which behavior broke.
|
|
92
|
+
A wide test fails together with others, so the failure does not point at one behavior.
|
|
93
|
+
|
|
94
|
+
## Obvious
|
|
95
|
+
|
|
96
|
+
Separate arrange, act, and assert with a blank line.
|
|
97
|
+
The input that changes the result sits in that test. A fixture two hundred lines away turns the expected value into a puzzle.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
def test_nan_in_a_tensor_is_rejected():
|
|
101
|
+
outputs = {"logits": torch.tensor([1.0, float("nan"), 3.0])}
|
|
102
|
+
|
|
103
|
+
with pytest.raises(CorrectnessValueError, match="NaN"):
|
|
104
|
+
check_output_correctness(outputs)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Name the behavior: `test_dynamic_shapes_are_rejected`.
|
|
108
|
+
`test_1`, `test_ok`, and `test_works` are not names.
|
|
109
|
+
A docstring that repeats the name adds nothing. Delete it.
|
|
110
|
+
Write one sentence when the assert only stands in for the intent. Two hashes can differ because the object is hashed by identity, and the test name cannot carry that reason.
|
|
111
|
+
|
|
112
|
+
A value used once stays inline. A variable earns its place when it separates `expected_*` from `actual_*`, or when the same literal is the cause in both arrange and assert.
|
|
113
|
+
|
|
114
|
+
## Show what matters
|
|
115
|
+
|
|
116
|
+
Repeat two tests when the repetition is the example.
|
|
117
|
+
Extract on the third copy, and only the part that does not change the result.
|
|
118
|
+
Duplication of knowledge (one constructor, one device, one tolerance used everywhere) may be one helper.
|
|
119
|
+
Duplication of an example stays duplicated. Merging those examples hides which input produced which output.
|
|
120
|
+
|
|
121
|
+
The helper takes the values the assertion depends on. Defaults cover the rest.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
def linear(in_features, out_features, weight):
|
|
125
|
+
layer = torch.nn.Linear(in_features, out_features, bias=False)
|
|
126
|
+
with torch.no_grad():
|
|
127
|
+
layer.weight.copy_(weight)
|
|
128
|
+
return layer
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_linear_scales_the_input():
|
|
132
|
+
layer = linear(2, 1, torch.tensor([[2.0, 0.0]]))
|
|
133
|
+
|
|
134
|
+
actual = layer(torch.tensor([[3.0, 4.0]]))
|
|
135
|
+
|
|
136
|
+
torch.testing.assert_close(actual, torch.tensor([[6.0]]))
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The weight is visible. Bias, dtype, and device are not the story, so they stay inside `linear`.
|
|
140
|
+
A helper that also picks the weight has hidden the test.
|
|
141
|
+
|
|
142
|
+
Write test functions. Request a fixture by naming the argument.
|
|
143
|
+
`unittest.TestCase` and `setUp` hide that dependency. Do not add them.
|
|
144
|
+
Do not inherit a test base class. A subclass that overrides setup hides the cause in another class.
|
|
145
|
+
Do not hide the cause in `setup_method` or a new autouse fixture.
|
|
146
|
+
|
|
147
|
+
A fixture may build the object under test and inject boring dependencies.
|
|
148
|
+
The scenario stays in the test.
|
|
149
|
+
Function scope is the default. A wider scope hands every test the same instance.
|
|
150
|
+
Use that only for an expensive resource the tests do not mutate. A shared model or a shared cache leaks.
|
|
151
|
+
A fixture the test does not need can fail first, and the test never runs. Keep the list short.
|
|
152
|
+
The root `conftest.py` already clears the module registry and points the cache at `tmp_path`. Do not reinvent it.
|
|
153
|
+
Shared toys live in `tests/toy_models` and `tests/utilities`. Add one when a second test needs the same irrelevant detail.
|
|
154
|
+
|
|
155
|
+
## Fixed data
|
|
156
|
+
|
|
157
|
+
Prefer `torch.tensor([...])`, `torch.arange`, or `torch.zeros`.
|
|
158
|
+
`torch.randn` is allowed only with a literal seed in that test, and only when a literal tensor will not do.
|
|
159
|
+
The failure message should contain the input. A random tensor does not.
|
|
160
|
+
No clock, no random id, no "whatever the model returned."
|
|
161
|
+
If production reads the clock, pass the time in. If it cannot, patch the clock at that boundary with a literal. Do not call `datetime.now()` in the test.
|
|
162
|
+
|
|
163
|
+
## Assert the value
|
|
164
|
+
|
|
165
|
+
Assert the value the caller observes: a tensor, a name, a shape, a chosen backend, or a raised type and its message.
|
|
166
|
+
Use a plain `assert`. pytest prints both sides of a comparison.
|
|
167
|
+
`assert flag`, `assert result is not None`, and `assert ok` hide that value. Write `assert actual.shape == (4, 8)`.
|
|
168
|
+
A test returns `None`. `return actual == expected` is ignored, and the test stays green.
|
|
169
|
+
|
|
170
|
+
Scalars use `pytest.approx`. Tensors use `torch.testing.assert_close`.
|
|
171
|
+
Do not write `abs(a - b) < tol`.
|
|
172
|
+
|
|
173
|
+
## Behavior
|
|
174
|
+
|
|
175
|
+
Assert what the caller sees.
|
|
176
|
+
|
|
177
|
+
- Forward outputs after `tune`.
|
|
178
|
+
- Which backend won, read from the result.
|
|
179
|
+
- Inspect names, shapes, and dtypes.
|
|
180
|
+
- Save, then load, then forward.
|
|
181
|
+
- A rejected input: dynamic shapes, empty recording, CPU where XPU is required, NaN, Inf.
|
|
182
|
+
|
|
183
|
+
Do not lock call order. Do not call a private function.
|
|
184
|
+
A behavior you can reach only through `_helper` is a design problem in production. Test the public method. Ask before reshaping production code to make the test possible.
|
|
185
|
+
|
|
186
|
+
This is a change detector. It fails on a rename and passes on a wrong answer:
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
build = mocker.patch.object(backend, "build")
|
|
190
|
+
|
|
191
|
+
tune(module, sample)
|
|
192
|
+
|
|
193
|
+
build.assert_called_once()
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Delete that test, and in its place assert the tensor, the selected backend, or the rejection.
|
|
197
|
+
|
|
198
|
+
## Doubles and stand-ins
|
|
199
|
+
|
|
200
|
+
A unit test here may use its real neighbors. A real strategy next to a real toy model is the point.
|
|
201
|
+
A bug in the neighbor may fail this test. Follow it. Do not mock every neighbor to keep the test solitary.
|
|
202
|
+
|
|
203
|
+
Assert the output first, then the state left behind: a file under `tmp_path`, or the backend stored on the module.
|
|
204
|
+
A recorded call is last. Use it only for a side effect that leaves the process, such as a download or an external log sink.
|
|
205
|
+
Do not assert a query that only supplied data. That assertion breaks when the query is inlined, and it never checked the answer.
|
|
206
|
+
|
|
207
|
+
Use the real collaborator when it is in-process and cheap: a toy `nn.Module`, real `SampleMetadata`, the real strategy.
|
|
208
|
+
The cache directory and the checkpoint files are ours. Exercise the real code against `tmp_path`.
|
|
209
|
+
A double belongs on a boundary we do not control: a download, a clock, a backend this machine cannot run.
|
|
210
|
+
|
|
211
|
+
Do not mock what we do not own. `torch`, `timm`, `diffusers`, `transformers`, and OpenVINO are not ours.
|
|
212
|
+
Mocking their types couples the test to their layout. A new release breaks the test and the behavior can still be wrong.
|
|
213
|
+
Pass our own collaborator in when the production code accepts one.
|
|
214
|
+
When a failure cannot be produced for real, a timeout or a refused download, patch the name where the code under test looks it up.
|
|
215
|
+
`mocker` and `monkeypatch` put the name back. A patch that leaks into the next test is shared mutable state.
|
|
216
|
+
|
|
217
|
+
Name the stand-in for the role it actually plays.
|
|
218
|
+
|
|
219
|
+
- A stub returns a fixed value so the subject can run.
|
|
220
|
+
- A fake is a simpler working stand-in. It must still do the job. An echo that returns the input is not OpenVINO, Inductor, or an XPU graph.
|
|
221
|
+
- A mock that records calls asserts structure. That is the change detector above.
|
|
222
|
+
|
|
223
|
+
A green test against a stand-in that behaves differently from production proves the stand-in. The real compiler, the real device, the real checkpoint format run in the test that claims to cover them, or that test does not exist.
|
|
224
|
+
|
|
225
|
+
## The tradeoff
|
|
226
|
+
|
|
227
|
+
Make a test deterministic, specific, and sensitive to behavior.
|
|
228
|
+
Make it insensitive to structure. A rename of a helper must not turn it red.
|
|
229
|
+
Order does not matter, and one test must not leave state for the next.
|
|
230
|
+
|
|
231
|
+
Closer to a full production run, the test gets slower and less specific.
|
|
232
|
+
That is why a branch in a pure function stays a unit test, and a real compiler path is functional.
|
|
233
|
+
Do not run a slow test to learn what a literal example already shows.
|
|
234
|
+
|
|
235
|
+
## Where it runs
|
|
236
|
+
|
|
237
|
+
| Kind | Place | Marker | Proves |
|
|
238
|
+
|---|---|---|---|
|
|
239
|
+
| Unit | `tests/unit/` | none | One behavior. Toy model. No download. |
|
|
240
|
+
| Functional | `tests/functional/` | `functional` | One real path: a ResNet, a tokenizer, one backend. |
|
|
241
|
+
| Long | either tree | `nightly` | The same, when it is too slow for the normal run. |
|
|
242
|
+
|
|
243
|
+
Test a new fact in the smallest test that can see it. A branch in a pure function is a unit test.
|
|
244
|
+
Move up when the bug lives in the wiring: export, device, weights, save/load on a real module.
|
|
245
|
+
A functional test is still one scenario, with a literal or an eager oracle.
|
|
246
|
+
Do not boot a full download to test a pure function.
|
|
247
|
+
Do not cover a compiler by mocking it.
|
|
248
|
+
|
|
249
|
+
Unit tests are hermetic. No network. No dependence on another test. No leftover global state.
|
|
250
|
+
The registry fixture exists because global state leaks. Do not add a second global.
|
|
251
|
+
|
|
252
|
+
Device comes from the `torch_device` fixture. `TORCH_TWEAK_TESTS_USE_DEVICE` overrides it.
|
|
253
|
+
Hardcode `torch.device("xpu")` only when the behavior is XPU-only, and mark the test with `requires_xpu` from `tests.utilities.helpers`.
|
|
254
|
+
Do not branch the expected value on CPU versus XPU.
|
|
255
|
+
|
|
256
|
+
A new file is `test_<behavior>.py`.
|
|
257
|
+
Do not number a new functional file. `012_torch_tweak_...` is an old sequence, not a name.
|
|
258
|
+
|
|
259
|
+
Skip a test only when this machine cannot run it. Missing XPU uses `requires_xpu` from `tests.utilities.helpers`.
|
|
260
|
+
`xfail` marks a known defect. Name that defect in `reason`.
|
|
261
|
+
`skip`, `skipif`, and `xfail` take `reason`.
|
|
262
|
+
Do not skip a test to hide a failure.
|
|
263
|
+
|
|
264
|
+
A page of arrange in a unit test means the production object asks for too much. Say so.
|
|
265
|
+
Do not cover that with a base class or a god fixture.
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
uv run pytest -m "not functional and not nightly"
|
|
269
|
+
uv run pytest -m functional
|
|
270
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
.idea/
|
|
4
|
+
.git/
|
|
5
|
+
.gitbu/
|
|
6
|
+
.eggs/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.venv/
|
|
9
|
+
.gitignore
|
|
10
|
+
.ruff/
|
|
11
|
+
.tox/
|
|
12
|
+
.pytype/
|
|
13
|
+
.mypy_cache/
|
|
14
|
+
*.egg-info/
|
|
15
|
+
build/
|
|
16
|
+
workspace/
|
|
17
|
+
checkpoints/
|
|
18
|
+
tmp/
|
|
19
|
+
|
|
20
|
+
**/*.pyc
|
|
21
|
+
**/*.pyi
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
# http://editorconfig.org
|
|
4
|
+
|
|
5
|
+
root = true
|
|
6
|
+
|
|
7
|
+
[*]
|
|
8
|
+
indent_style = space
|
|
9
|
+
indent_size = 4
|
|
10
|
+
trim_trailing_whitespace = true
|
|
11
|
+
insert_final_newline = true
|
|
12
|
+
charset = utf-8
|
|
13
|
+
end_of_line = lf
|
|
14
|
+
|
|
15
|
+
[*.bat]
|
|
16
|
+
indent_style = tab
|
|
17
|
+
end_of_line = crlf
|
|
18
|
+
|
|
19
|
+
[LICENSE]
|
|
20
|
+
insert_final_newline = false
|
|
21
|
+
|
|
22
|
+
[Makefile]
|
|
23
|
+
indent_style = tab
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Run dependencies versions update
|
|
2
|
+
version: 2
|
|
3
|
+
|
|
4
|
+
updates:
|
|
5
|
+
- package-ecosystem: "uv"
|
|
6
|
+
directories:
|
|
7
|
+
- "/"
|
|
8
|
+
- "/examples/*/"
|
|
9
|
+
schedule:
|
|
10
|
+
interval: "weekly"
|
|
11
|
+
day: "monday"
|
|
12
|
+
commit-message:
|
|
13
|
+
prefix: "chore(deps)"
|
|
14
|
+
groups:
|
|
15
|
+
security-updates:
|
|
16
|
+
applies-to: security-updates
|
|
17
|
+
patterns:
|
|
18
|
+
- "*"
|
|
19
|
+
test-dependencies:
|
|
20
|
+
applies-to: version-updates
|
|
21
|
+
patterns:
|
|
22
|
+
- "pytest*"
|
|
23
|
+
doc-dependencies:
|
|
24
|
+
applies-to: version-updates
|
|
25
|
+
patterns:
|
|
26
|
+
- "properdocs*"
|
|
27
|
+
- "mike*"
|
|
28
|
+
dev-dependencies:
|
|
29
|
+
applies-to: version-updates
|
|
30
|
+
patterns:
|
|
31
|
+
- "*"
|
|
32
|
+
|
|
33
|
+
- package-ecosystem: "github-actions"
|
|
34
|
+
directory: "/.github/workflows"
|
|
35
|
+
schedule:
|
|
36
|
+
interval: "weekly"
|
|
37
|
+
day: "monday"
|
|
38
|
+
commit-message:
|
|
39
|
+
prefix: "chore(deps)"
|
|
40
|
+
groups:
|
|
41
|
+
github-actions-dependencies:
|
|
42
|
+
applies-to: version-updates
|
|
43
|
+
patterns:
|
|
44
|
+
- "*"
|