Spaces:
Building
Building
File size: 1,397 Bytes
3f10400 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#!/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 ===")
|