zazaman commited on
Commit
d2cecb3
·
1 Parent(s): e7a0c9a

Add automatic architecture detection and binary selection for llama.cpp

Browse files
Files changed (1) hide show
  1. llm_clients/qwen_translator.py +37 -6
llm_clients/qwen_translator.py CHANGED
@@ -97,8 +97,38 @@ class QwenTranslatorClient(LlmClient):
97
  # If not found, we'll search after extraction
98
  binary_path = binary_dir / "main" # Default to 'main' (standard llama.cpp binary name)
99
 
100
- # Download the zip file
101
- zip_url = "https://github.com/ggml-org/llama.cpp/releases/download/b6995/llama-b6995-bin-ubuntu-x64.zip"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  zip_path = binary_dir / "llama-binary.zip"
103
 
104
  try:
@@ -191,8 +221,8 @@ class QwenTranslatorClient(LlmClient):
191
 
192
  # Test if binary can actually run (check architecture compatibility)
193
  print(f" 🔍 Testing binary compatibility...", flush=True)
194
- machine = platform.machine()
195
- print(f" System architecture: {machine}", flush=True)
196
 
197
  try:
198
  # Try to run the binary with --help to verify it works
@@ -230,10 +260,11 @@ class QwenTranslatorClient(LlmClient):
230
 
231
  raise RuntimeError(
232
  f"Binary architecture mismatch. The downloaded binary is not compatible with this system.\n"
233
- f"System architecture: {machine}\n"
 
234
  f"Binary info: {file_info}\n"
235
  f"Error: {error_msg}\n"
236
- f"The Ubuntu x64 binary may not be compatible with this system. "
237
  f"Translation feature requires a compatible llama.cpp binary for this architecture."
238
  ) from os_error
239
  else:
 
97
  # If not found, we'll search after extraction
98
  binary_path = binary_dir / "main" # Default to 'main' (standard llama.cpp binary name)
99
 
100
+ # Detect architecture and select appropriate binary
101
+ machine = platform.machine().lower()
102
+ is_linux = sys.platform.startswith('linux')
103
+
104
+ # Map architectures to available binaries
105
+ # Available: ubuntu-x64, ubuntu-s390x, ubuntu-vulkan-x64, macos-arm64, macos-x64, win-cpu-x64, win-cpu-arm64
106
+ binary_name = "unknown"
107
+ if is_linux:
108
+ if machine in ['x86_64', 'amd64']:
109
+ # Try standard Ubuntu x64 first (most common)
110
+ zip_url = "https://github.com/ggml-org/llama.cpp/releases/download/b6996/llama-b6996-bin-ubuntu-x64.zip"
111
+ binary_name = "ubuntu-x64"
112
+ elif machine == 's390x':
113
+ zip_url = "https://github.com/ggml-org/llama.cpp/releases/download/b6996/llama-b6996-bin-ubuntu-s390x.zip"
114
+ binary_name = "ubuntu-s390x"
115
+ elif machine in ['aarch64', 'arm64']:
116
+ # No ARM Linux binary available, will need to handle this
117
+ raise RuntimeError(
118
+ f"ARM64 Linux architecture detected, but no pre-built ARM64 Linux binary is available. "
119
+ f"Available binaries are for x86_64, s390x, macOS ARM64, and Windows. "
120
+ f"Translation feature cannot work on ARM64 Linux without compiling from source."
121
+ )
122
+ else:
123
+ # Try x64 as fallback
124
+ print(f" ⚠️ Unknown Linux architecture '{machine}', trying x64 binary...", flush=True)
125
+ zip_url = "https://github.com/ggml-org/llama.cpp/releases/download/b6996/llama-b6996-bin-ubuntu-x64.zip"
126
+ binary_name = "ubuntu-x64"
127
+ else:
128
+ # Non-Linux systems (shouldn't reach here due to earlier check, but just in case)
129
+ raise RuntimeError(f"Unsupported platform: {sys.platform}")
130
+
131
+ print(f" Selected binary: {binary_name} for architecture: {machine}", flush=True)
132
  zip_path = binary_dir / "llama-binary.zip"
133
 
134
  try:
 
221
 
222
  # Test if binary can actually run (check architecture compatibility)
223
  print(f" 🔍 Testing binary compatibility...", flush=True)
224
+ detected_machine = platform.machine()
225
+ print(f" System architecture: {detected_machine}", flush=True)
226
 
227
  try:
228
  # Try to run the binary with --help to verify it works
 
260
 
261
  raise RuntimeError(
262
  f"Binary architecture mismatch. The downloaded binary is not compatible with this system.\n"
263
+ f"System architecture: {detected_machine}\n"
264
+ f"Binary selected: {binary_name}\n"
265
  f"Binary info: {file_info}\n"
266
  f"Error: {error_msg}\n"
267
+ f"The binary may require specific shared libraries or a different architecture. "
268
  f"Translation feature requires a compatible llama.cpp binary for this architecture."
269
  ) from os_error
270
  else: