Spaces:
Paused
Paused
| #!/usr/bin/env python3 | |
| """ | |
| Test CPU - Script di Prova | |
| =========================== | |
| Verifica che l'esecuzione remota funzioni correttamente (senza GPU). | |
| Eseguilo con: python3 launcher.py test_cpu.py | |
| """ | |
| import sys | |
| import platform | |
| import os | |
| print("=" * 60) | |
| print("๐ TEST ESECUZIONE REMOTA (CPU)") | |
| print("=" * 60) | |
| # 1. Info Sistema | |
| print("\n๐ Informazioni Sistema:") | |
| print(f" Python: {sys.version}") | |
| print(f" Platform: {platform.platform()}") | |
| print(f" Machine: {platform.machine()}") | |
| print(f" Processor: {platform.processor() or 'N/A'}") | |
| # 2. Info CPU | |
| print("\n๐ฅ๏ธ CPU:") | |
| try: | |
| cpu_count = os.cpu_count() | |
| print(f" Core disponibili: {cpu_count}") | |
| except: | |
| print(" Core: N/A") | |
| # 3. Test Calcolo | |
| print("\nโก Test Calcolo:") | |
| import time | |
| # Calcolo intensivo semplice | |
| start = time.time() | |
| result = sum(i * i for i in range(1_000_000)) | |
| elapsed = time.time() - start | |
| print(f" Somma quadrati (1M numeri): {result:,}") | |
| print(f" Tempo: {elapsed:.4f} secondi") | |
| # 4. Test PyTorch (se disponibile) | |
| print("\n๐ฅ Test PyTorch:") | |
| try: | |
| import torch | |
| print(f" PyTorch version: {torch.__version__}") | |
| print(f" CUDA disponibile: {torch.cuda.is_available()}") | |
| # Operazione su CPU | |
| a = torch.randn(1000, 1000) | |
| b = torch.randn(1000, 1000) | |
| start = time.time() | |
| c = torch.matmul(a, b) | |
| elapsed = time.time() - start | |
| print(f" Matmul 1000x1000 (CPU): {elapsed:.4f}s") | |
| print(f" Risultato shape: {c.shape}") | |
| except ImportError: | |
| print(" PyTorch non installato") | |
| except Exception as e: | |
| print(f" Errore: {e}") | |
| # 5. Memoria | |
| print("\n๐พ Memoria:") | |
| try: | |
| import subprocess | |
| mem = subprocess.check_output(['free', '-h']).decode() | |
| for line in mem.split('\n')[:2]: | |
| print(f" {line}") | |
| except: | |
| print(" Info memoria non disponibile") | |
| print("\n" + "=" * 60) | |
| print("โ TEST CPU COMPLETATO!") | |
| print(" L'esecuzione remota funziona correttamente.") | |
| print("=" * 60) | |