TobDeBer commited on
Commit
a972051
·
verified ·
1 Parent(s): 3c2d17d

server on CUDA

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -41,14 +41,9 @@ except subprocess.CalledProcessError:
41
  except FileNotFoundError:
42
  platform = "CPU"
43
 
44
- print(f"Detected platform {platform}")
45
 
46
- # login to HF with space secret and download gguf and executable
47
- #hf_token = os.getenv("HF_TOKEN") # Set this in your environment before running
48
- #if hf_token:
49
- # login(token=hf_token)
50
- #else:
51
- # raise ValueError("Hugging Face token not found. Please set HF_TOKEN environment variable.")
52
 
53
  gguf_name = "granite-4.0-tiny-preview-Q4_K_M.gguf"
54
  gguf_path = hf_hub_download(
@@ -64,11 +59,16 @@ exe_path = hf_hub_download(
64
  filename=exe_name,
65
  local_dir="."
66
  )
 
67
 
68
  # start llama-server
69
  subprocess.run(["chmod", "+x", exe_name])
70
  command = ["./" + exe_name, "-m", gguf_name, "--temp", "0.0", "-c", "2048", "-t", "8", "--port", "8081"]
71
- process = subprocess.Popen(command)
 
 
 
 
72
  print(f"Llama-server process started with PID {process.pid}")
73
 
74
  custom_theme = ResearchMonochrome()
 
41
  except FileNotFoundError:
42
  platform = "CPU"
43
 
44
+ platform = "CUDA" # override for ZERO, because the GPU is not available at the time download decision is done
45
 
46
+ print(f"Detected platform {platform}")
 
 
 
 
 
47
 
48
  gguf_name = "granite-4.0-tiny-preview-Q4_K_M.gguf"
49
  gguf_path = hf_hub_download(
 
59
  filename=exe_name,
60
  local_dir="."
61
  )
62
+ server_env = os.environ.copy()
63
 
64
  # start llama-server
65
  subprocess.run(["chmod", "+x", exe_name])
66
  command = ["./" + exe_name, "-m", gguf_name, "--temp", "0.0", "-c", "2048", "-t", "8", "--port", "8081"]
67
+ if platform == "CUDA":
68
+ # -ngl 999 tells the server to attempt to offload 999 layers (essentially all of them)
69
+ # to the GPU for execution. Without this, it runs on the CPU, even with the CUDA binary.
70
+ command.extend(["-ngl", "999"])
71
+ process = subprocess.Popen(command, env=server_env)
72
  print(f"Llama-server process started with PID {process.pid}")
73
 
74
  custom_theme = ResearchMonochrome()