Skip to content

Commit bf0af80

Browse files
authored
Merge pull request #1673 from containers/mlx-fixes
mlx fixes
2 parents 99f56a7 + 5b20aa4 commit bf0af80

File tree

6 files changed

+31
-33
lines changed

6 files changed

+31
-33
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,6 @@ RamaLama is available via PyPi at [https://pypi.org/project/ramalama](https://py
116116
pip install ramalama
117117
```
118118

119-
### Install via Homebrew
120-
```
121-
brew install ramalama
122-
```
123-
124119
### Install script (Linux and macOS)
125120
Install RamaLama by running:
126121
```

install.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ is_python3_at_least_310() {
129129
python3 -c 'import sys; exit(0 if sys.version_info >= (3, 10) else 1)'
130130
}
131131

132+
install_uv() {
133+
local host="raw.githubusercontent.com"
134+
local install_uv_url="https://$host/containers/ramalama/s/install-uv.sh"
135+
curl -fsSL "$install_uv_url" | bash
136+
echo
137+
}
138+
132139
main() {
133140
set -e -o pipefail
134141

@@ -151,14 +158,13 @@ main() {
151158
fi
152159

153160
if available brew && brew install ramalama; then
161+
install_uv
162+
uv tool install mlx-lm
154163
return 0
155164
fi
156165
fi
157166

158-
local host="raw.githubusercontent.com"
159-
local install_uv_url="https://$host/containers/ramalama/s/install-uv.sh"
160-
curl -fsSL "$install_uv_url" | bash
161-
echo
167+
install_uv
162168
uv tool install --force --python python3.12 ramalama
163169
print_success_info
164170
}

ramalama/cli.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from ramalama.common import accel_image, get_accel, perror
2727
from ramalama.config import CONFIG
2828
from ramalama.logger import configure_logger, logger
29-
from ramalama.model import MODEL_TYPES
29+
from ramalama.model import MODEL_TYPES, trim_model_name
3030
from ramalama.model_factory import ModelFactory, New
3131
from ramalama.model_inspect.error import ParseError
3232
from ramalama.model_store.global_store import GlobalModelStore
@@ -474,12 +474,7 @@ def _list_models_from_store(args):
474474
if not args.all and is_partially_downloaded:
475475
continue
476476

477-
if model.startswith("huggingface://"):
478-
model = model.replace("huggingface://", "hf://", 1)
479-
480-
if not model.startswith("ollama://") and not model.startswith("oci://"):
481-
model = model.removesuffix(":latest")
482-
477+
model = trim_model_name(model)
483478
size_sum = 0
484479
last_modified = 0.0
485480
for file in files:

ramalama/model.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def is_split_file_model(model_path):
6363
return bool(re.match(SPLIT_MODEL_RE, model_path))
6464

6565

66+
def trim_model_name(model):
67+
if model.startswith("huggingface://"):
68+
model = model.replace("huggingface://", "hf://", 1)
69+
70+
if not model.startswith("ollama://") and not model.startswith("oci://"):
71+
model = model.removesuffix(":latest")
72+
73+
return model
74+
75+
6676
class ModelBase:
6777
def __not_implemented_error(self, param):
6878
return NotImplementedError(f"ramalama {param} for '{type(self).__name__}' not implemented")
@@ -479,10 +489,7 @@ def _build_mlx_exec_args(self, subcommand: str, model_path: str, args, extra: li
479489
Optional list of extra arguments to append verbatim.
480490
"""
481491
exec_args = [
482-
"python",
483-
"-m",
484-
"mlx_lm",
485-
subcommand,
492+
"mlx_lm.server",
486493
"--model",
487494
shlex.quote(model_path),
488495
]
@@ -849,6 +856,7 @@ def inspect(self, args):
849856
print(ModelInfoBase(model_name, model_registry, model_path).serialize(json=args.json))
850857

851858
def print_pull_message(self, model_name):
859+
model_name = trim_model_name(model_name)
852860
# Write messages to stderr
853861
perror(f"Downloading {model_name} ...")
854862
perror(f"Trying to pull {model_name} ...")

test/system/080-mlx.bats

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function skip_if_no_mlx() {
5858
run_ramalama --runtime=mlx --dryrun run ${MODEL}
5959
is "$status" "0" "MLX run should work"
6060
# Should use python -m mlx_lm server for the server process
61-
is "$output" ".*python.*-m.*mlx_lm server.*" "should use MLX server command"
61+
is "$output" ".*mlx_lm.server.*" "should use MLX server command"
6262
is "$output" ".*--port.*" "should include port specification"
6363
}
6464

@@ -69,7 +69,7 @@ function skip_if_no_mlx() {
6969
prompt="Hello, how are you?"
7070
run_ramalama --runtime=mlx --dryrun run ${MODEL} "$prompt"
7171
is "$status" "0" "MLX run with prompt should work"
72-
is "$output" ".*python.*-m.*mlx_lm server.*" "should use MLX server command"
72+
is "$output" ".*mlx_lm.server.*" "should use MLX server command"
7373
is "$output" ".*--port.*" "should include port specification"
7474
}
7575

@@ -98,7 +98,7 @@ function skip_if_no_mlx() {
9898
run_ramalama --runtime=mlx --dryrun serve ${MODEL}
9999
is "$status" "0" "MLX serve should work"
100100
# Should use python -m mlx_lm.server
101-
is "$output" ".*python.*-m.*mlx_lm server.*" "should use MLX server command"
101+
is "$output" ".*mlx_lm.server.*" "should use MLX server command"
102102
is "$output" ".*--port.*8080.*" "should include default port"
103103
}
104104

@@ -145,7 +145,7 @@ function skip_if_no_mlx() {
145145
model="ollama://smollm:135m"
146146
run_ramalama --runtime=mlx --dryrun run "$model"
147147
is "$status" "0" "MLX should work with ollama model format"
148-
is "$output" ".*python.*-m.*mlx_lm server.*" "should use MLX server command"
148+
is "$output" ".*mlx_lm.server.*" "should use MLX server command"
149149
}
150150

151151
@test "ramalama --runtime=mlx works with huggingface model format" {
@@ -155,7 +155,7 @@ function skip_if_no_mlx() {
155155
model="huggingface://microsoft/DialoGPT-small"
156156
run_ramalama --runtime=mlx --dryrun run "$model"
157157
is "$status" "0" "MLX should work with huggingface model format"
158-
is "$output" ".*python.*-m.*mlx_lm server.*" "should use MLX server command"
158+
is "$output" ".*mlx_lm.server.*" "should use MLX server command"
159159
}
160160

161161
@test "ramalama --runtime=mlx rejects --name option" {

test/unit/test_model.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ def test_mlx_serve_args(self):
143143
exec_args = model.mlx_serve(args, "/path/to/model")
144144

145145
expected_args = [
146-
"python",
147-
"-m",
148-
"mlx_lm",
149-
"server",
146+
"mlx_lm.server",
150147
"--model",
151148
"/path/to/model",
152149
"--temp",
@@ -275,10 +272,7 @@ def test_mlx_build_exec_args_includes_server_subcommand(self, mock_machine, mock
275272
exec_args = model._build_mlx_exec_args("server", "/path/to/model", args, ["--port", "8080"])
276273

277274
expected_args = [
278-
"python",
279-
"-m",
280-
"mlx_lm",
281-
"server",
275+
"mlx_lm.server",
282276
"--model",
283277
"/path/to/model",
284278
"--temp",

0 commit comments

Comments
 (0)