Spaces:
Building
Building
| #!/usr/bin/env python3 | |
| """ | |
| Simple GPU test for HuggingFace Spaces. | |
| Run this in the HuggingFace Space terminal to verify GPU configuration. | |
| """ | |
| print("=== HuggingFace Space GPU Test ===\n") | |
| # Test 1: PyTorch CUDA | |
| print("1. PyTorch CUDA Test:") | |
| try: | |
| import torch | |
| print(f"Is CUDA available: {torch.cuda.is_available()}") | |
| if torch.cuda.is_available(): | |
| print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}") | |
| # Test computation | |
| x = torch.randn(1000, 1000).cuda() | |
| y = torch.matmul(x, x) | |
| print(f"GPU computation test: ✓ Success (computed 1000x1000 matrix multiplication)") | |
| except ImportError: | |
| print("PyTorch not installed") | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| print("\n2. SpaCy GPU Test:") | |
| try: | |
| import spacy | |
| gpu_id = spacy.prefer_gpu() | |
| print(f"SpaCy GPU enabled: {gpu_id is not False}") | |
| if gpu_id is not False: | |
| print(f"Using GPU device: {gpu_id}") | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| print("\n3. Quick Model Test:") | |
| try: | |
| import spacy | |
| # This will use GPU if available | |
| nlp = spacy.load("en_core_web_trf") | |
| doc = nlp("This is a GPU test.") | |
| print(f"Model loaded and processed {len(doc)} tokens") | |
| print("✓ Transformer model working correctly") | |
| except Exception as e: | |
| print(f"Error loading model: {e}") | |
| print("\n=== Test Complete ===") | |