Download cognitive_mapping_probe/utils.py from neuralworm/cognitive_mapping_probe_4: direct link, hf CLI and curl.
- Browser
- Download file 819 Bytes
-
https://huggingface.co/spaces/neuralworm/cognitive_mapping_probe_4/resolve/main/cognitive_mapping_probe/utils.py
- Command line
-
hf download hf://spaces/neuralworm/cognitive_mapping_probe_4/cognitive_mapping_probe/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/neuralworm/cognitive_mapping_probe_4/resolve/main/cognitive_mapping_probe/utils.py
819 Bytes
| import os | |
| import sys | |
| import gc | |
| import torch | |
| # --- Centralized Debugging Control --- | |
| DEBUG_ENABLED = os.environ.get("CMP_DEBUG", "0") == "1" | |
| def dbg(*args, **kwargs): | |
| """A controlled debug print function.""" | |
| if DEBUG_ENABLED: | |
| print("[DEBUG]", *args, **kwargs, file=sys.stderr, flush=True) | |
| # --- NEU: Zentrale Funktion zur Speicherbereinigung --- | |
| def cleanup_memory(): | |
| """ | |
| Eine zentrale, global verfügbare Funktion zum Aufräumen von CPU- und GPU-Speicher. | |
| Dies stellt sicher, dass die Speicherverwaltung konsistent und an einer einzigen Stelle erfolgt. | |
| """ | |
| dbg("Cleaning up memory (centralized)...") | |
| # Python's garbage collector | |
| gc.collect() | |
| # PyTorch's CUDA cache | |
| if torch.cuda.is_available(): | |
| torch.cuda.empty_cache() | |
| dbg("Memory cleanup complete.") | |