2025-01-28 13:56:00 -08:00
|
|
|
import importlib.util
|
2025-01-29 15:25:10 -08:00
|
|
|
import logging
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2024-11-01 16:57:19 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2025-01-29 15:30:39 -08:00
|
|
|
|
2024-11-01 16:57:19 +00:00
|
|
|
def check_poppler_version():
|
|
|
|
try:
|
2025-01-29 15:30:39 -08:00
|
|
|
result = subprocess.run(["pdftoppm", "-h"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
2024-11-01 17:13:11 +00:00
|
|
|
if result.returncode == 0 and result.stderr.startswith("pdftoppm"):
|
2024-11-01 16:57:19 +00:00
|
|
|
logger.info("pdftoppm is installed and working.")
|
|
|
|
else:
|
2025-01-29 15:47:57 -08:00
|
|
|
logger.error("pdftoppm is installed but returned an error.")
|
2024-11-01 16:57:19 +00:00
|
|
|
sys.exit(1)
|
|
|
|
except FileNotFoundError:
|
|
|
|
logger.error("pdftoppm is not installed.")
|
2025-01-27 18:30:41 +00:00
|
|
|
logger.error("Check the README in the https://github.com/allenai/olmocr/blob/main/README.md for installation instructions")
|
2024-11-01 17:13:11 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2025-01-29 15:30:39 -08:00
|
|
|
|
2025-01-28 13:56:00 -08:00
|
|
|
def check_sglang_version():
|
|
|
|
if importlib.util.find_spec("sglang") is None:
|
2025-01-29 15:47:57 -08:00
|
|
|
logger.error("Please make sure sglang is installed according to the latest instructions here: https://docs.sglang.ai/start/install.html")
|
2025-01-28 13:56:00 -08:00
|
|
|
logger.error("Sglang needs to be installed with a separate command in order to find all dependencies properly.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2025-01-29 15:30:39 -08:00
|
|
|
|
2025-03-03 15:54:47 -08:00
|
|
|
def check_torch_gpu_available(min_gpu_memory: int = 20 * 1024**3):
|
2025-01-29 21:48:56 +00:00
|
|
|
try:
|
|
|
|
import torch
|
|
|
|
except:
|
|
|
|
logger.error("Pytorch must be installed, visit https://pytorch.org/ for installation instructions")
|
|
|
|
raise
|
|
|
|
|
|
|
|
try:
|
2025-01-29 22:03:37 +00:00
|
|
|
gpu_memory = torch.cuda.get_device_properties(0).total_memory
|
2025-01-29 21:48:56 +00:00
|
|
|
assert gpu_memory >= min_gpu_memory
|
|
|
|
except:
|
|
|
|
logger.error(f"Torch was not able to find a GPU with at least {min_gpu_memory // (1024 ** 3)} GB of RAM.")
|
|
|
|
raise
|
|
|
|
|
2025-01-28 13:56:00 -08:00
|
|
|
|
2024-11-01 17:13:11 +00:00
|
|
|
if __name__ == "__main__":
|
2025-01-28 13:56:00 -08:00
|
|
|
check_poppler_version()
|
2025-01-29 15:30:39 -08:00
|
|
|
check_sglang_version()
|