|
| 1 | +""" |
| 2 | +Test that prebuilt wheel extraction includes all necessary Python files. |
| 3 | +
|
| 4 | +""" |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | + |
| 8 | +def test_cpp_extension_wrapper_files_exist(): |
| 9 | + """Verify that C++ extension wrapper Python files were extracted from prebuilt wheel.""" |
| 10 | + import tensorrt_llm |
| 11 | + |
| 12 | + trtllm_root = Path(tensorrt_llm.__file__).parent |
| 13 | + |
| 14 | + # C++ extensions that have Python wrapper files generated during build |
| 15 | + required_files = { |
| 16 | + 'deep_gemm': |
| 17 | + ['__init__.py', 'testing/__init__.py', 'utils/__init__.py'], |
| 18 | + 'deep_ep': ['__init__.py', 'buffer.py', 'utils.py'], |
| 19 | + 'flash_mla': ['__init__.py', 'flash_mla_interface.py'], |
| 20 | + } |
| 21 | + |
| 22 | + missing_files = [] |
| 23 | + for ext_dir, files in required_files.items(): |
| 24 | + for file in files: |
| 25 | + file_path = trtllm_root / ext_dir / file |
| 26 | + if not file_path.exists(): |
| 27 | + missing_files.append(str(file_path.relative_to(trtllm_root))) |
| 28 | + |
| 29 | + assert not missing_files, ( |
| 30 | + f"Missing Python wrapper files for C++ extensions: {missing_files}\n" |
| 31 | + f"This indicates setup.py may not be extracting Python files from prebuilt wheels.\n" |
| 32 | + f"Check setup.py extract_from_precompiled() function.") |
| 33 | + |
| 34 | + |
| 35 | +def test_cpp_extensions_importable(): |
| 36 | + """Verify that C++ extension wrappers can be imported successfully.""" |
| 37 | + import_tests = [ |
| 38 | + ('tensorrt_llm.deep_gemm', 'fp8_mqa_logits'), |
| 39 | + ('tensorrt_llm.deep_ep', 'Buffer'), |
| 40 | + ('tensorrt_llm.flash_mla', 'flash_mla_interface'), |
| 41 | + ] |
| 42 | + |
| 43 | + failed_imports = [] |
| 44 | + for module_name, attr_name in import_tests: |
| 45 | + try: |
| 46 | + module = __import__(module_name, fromlist=[attr_name]) |
| 47 | + if not hasattr(module, attr_name): |
| 48 | + failed_imports.append( |
| 49 | + f"{module_name}.{attr_name} (attribute not found)") |
| 50 | + except ImportError as e: |
| 51 | + failed_imports.append(f"{module_name} (ImportError: {e})") |
| 52 | + |
| 53 | + assert not failed_imports, ( |
| 54 | + f"Failed to import C++ extension wrappers: {failed_imports}\n" |
| 55 | + f"This may indicate missing Python files or circular import issues.") |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == '__main__': |
| 59 | + print("Testing C++ extension wrapper files...") |
| 60 | + test_cpp_extension_wrapper_files_exist() |
| 61 | + print("✅ All required Python files exist") |
| 62 | + |
| 63 | + print("\nTesting C++ extension imports...") |
| 64 | + test_cpp_extensions_importable() |
| 65 | + print("✅ All imports successful") |
| 66 | + |
| 67 | + print("\n✅ All tests passed!") |
0 commit comments