Skip to content

Commit 3dd52e3

Browse files
danielholandaamd-pworfolkjeremyfowers
authored
Release 6.1.4 (#304)
Co-authored-by: amd-pworfolk <[email protected]> Co-authored-by: Jeremy Fowers <[email protected]>
1 parent dc2a57e commit 3dd52e3

File tree

12 files changed

+162
-199
lines changed

12 files changed

+162
-199
lines changed

docs/lemonade/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ To prompt your LLM, try one of the following:
8383

8484
OGA iGPU:
8585
```bash
86-
lemonade -i microsoft/Phi-3-mini-4k-instruct oga-load --device igpu --dtype int4 llm-prompt -p "Hello, my thoughts are"
86+
lemonade -i microsoft/Phi-3-mini-4k-instruct oga-load --device igpu --dtype int4 llm-prompt -p "Hello, my thoughts are" -t
8787
```
8888

8989
Hugging Face:
9090
```bash
91-
lemonade -i facebook/opt-125m huggingface-load llm-prompt -p "Hello, my thoughts are"
91+
lemonade -i facebook/opt-125m huggingface-load llm-prompt -p "Hello, my thoughts are" -t
9292
```
9393

9494
The LLM will run with your provided prompt, and the LLM's response to your prompt will be printed to the screen. You can replace the `"Hello, my thoughts are"` with any prompt you like.
@@ -97,6 +97,9 @@ You can also replace the `facebook/opt-125m` with any Hugging Face checkpoint yo
9797
9898
You can also set the `--device` argument in `oga-load` and `huggingface-load` to load your LLM on a different device.
9999
100+
The `-t` (or `--template`) flag instructs lemonade to insert the prompt string into the model's chat template.
101+
This typically results in the model returning a higher quality response.
102+
100103
Run `lemonade huggingface-load -h` and `lemonade llm-prompt -h` to learn more about these tools.
101104

102105
## Accuracy

examples/lemonade/server/continue.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,23 @@ This will add a Continue tab to your VS Code Activity Bar.
3131
> Note: The following instructions are based on instructions from Continue found [here](https://docs.continue.dev/customize/model-providers/openai#openai-compatible-servers--apis)
3232
3333
1. Open the Continue tab in your VS Code Activity Bar.
34-
1. Click the gear icon at the top to open Settings.
35-
1. Under "Configuration", click "Open Config File".
36-
1. Replace the "models" key in the `config.json` with the following and save:
37-
38-
```json
39-
"models": [
40-
{
41-
"title": "Lemonade",
42-
"provider": "openai",
43-
"model": "Qwen-1.5-7B-Chat-Hybrid",
44-
"apiKey": "-",
45-
"apiBase": "http://localhost:8000/api/v0"
46-
}
47-
],
34+
1. Click the chat box. Some buttons will appear at the bottom of the box, including `Select model`.
35+
1. Click `Select model`, then `+ Add Chat model` to open the new model dialog box.
36+
1. Click the `config file` link at the very bottom of the dialog to open `config.yaml`.
37+
1. Replace the "models" key in the `config.yaml` with the following and save:
38+
39+
```yaml
40+
models:
41+
- name: Lemonade
42+
provider: openai
43+
model: Qwen-1.5-7B-Chat-Hybrid
44+
apiBase: http://localhost:8000/api/v0
45+
apiKey: none
4846
```
4947
48+
6. Close the dialog box.
49+
7. Click the chat box again. You should see `Lemonade` where you used to see `Select model`. Ready!
50+
5051
## Usage
5152

5253
> Note: see the Continue [user guide](https://docs.continue.dev/) to learn about all of their features.

installer/Installer.nsi

Lines changed: 29 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ OutFile "Lemonade_Server_Installer.exe"
1616
Var LogHandle
1717

1818
Var LEMONADE_SERVER_STRING
19-
Var LEMONADE_CONDA_ENV
2019
Var HYBRID_SELECTED
2120
Var HYBRID_CLI_OPTION
2221

@@ -54,9 +53,6 @@ SectionIn RO ; Read only, always installed
5453

5554
remove_dir:
5655
; Try to remove directory and verify it was successful
57-
58-
; Attempt conda remove of the env, to help speed things up
59-
ExecWait 'conda env remove -yp "$INSTDIR\$LEMONADE_CONDA_ENV"'
6056

6157
; Delete all remaining files
6258
RMDir /r "$INSTDIR"
@@ -103,97 +99,34 @@ SectionIn RO ; Read only, always installed
10399

104100
DetailPrint "- Packaged repo"
105101

106-
; Check if conda is available
107-
ExecWait 'where conda' $2
108-
DetailPrint "- Checked if conda is available"
109-
110-
; If conda is not found, show a message
111-
; Otherwise, continue with the installation
112-
StrCmp $2 "0" create_env conda_not_available
113-
114-
conda_not_available:
115-
DetailPrint "- Conda not installed."
116-
${IfNot} ${Silent}
117-
MessageBox MB_YESNO "Conda is not installed. Would you like to install Miniconda?" IDYES install_miniconda IDNO exit_installer
118-
${Else}
119-
Goto install_miniconda
120-
${EndIf}
121-
122-
exit_installer:
123-
DetailPrint "- Something went wrong. Exiting installer"
124-
Quit
125-
126-
install_miniconda:
127-
DetailPrint "-------------"
128-
DetailPrint "- Miniconda -"
129-
DetailPrint "-------------"
130-
DetailPrint "- Downloading Miniconda installer..."
131-
ExecWait 'curl -s -o "$TEMP\Miniconda3-latest-Windows-x86_64.exe" "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe"'
132-
133-
; Install Miniconda silently
134-
ExecWait '"$TEMP\Miniconda3-latest-Windows-x86_64.exe" /InstallationType=JustMe /AddToPath=1 /RegisterPython=0 /S /D=$PROFILE\miniconda3' $2
135-
; Check if Miniconda installation was successful
136-
${If} $2 == 0
137-
DetailPrint "- Miniconda installation successful"
138-
${IfNot} ${Silent}
139-
MessageBox MB_OK "Miniconda has been successfully installed."
140-
${EndIf}
141-
142-
StrCpy $R1 "$PROFILE\miniconda3\Scripts\conda.exe"
143-
Goto create_env
144-
145-
${Else}
146-
DetailPrint "- Miniconda installation failed"
147-
${IfNot} ${Silent}
148-
MessageBox MB_OK "Error: Miniconda installation failed. Installation will be aborted."
149-
${EndIf}
150-
Goto exit_installer
151-
${EndIf}
152-
153-
create_env:
154-
DetailPrint "---------------------"
155-
DetailPrint "- Conda Environment -"
156-
DetailPrint "---------------------"
157-
158-
DetailPrint "- Initializing conda..."
159-
; Use the appropriate conda executable
160-
${If} $R1 == ""
161-
StrCpy $R1 "conda"
162-
${EndIf}
163-
; Initialize conda (needed for systems where conda was previously installed but not initialized)
164-
nsExec::ExecToStack '"$R1" init'
165-
166-
DetailPrint "- Creating a Python 3.10 environment named '$LEMONADE_CONDA_ENV' in the installation directory: $INSTDIR..."
167-
ExecWait '"$R1" create -p "$INSTDIR\$LEMONADE_CONDA_ENV" python=3.10 -y' $R0
168-
169-
; Check if the environment creation was successful (exit code should be 0)
170-
StrCmp $R0 0 install_lemonade env_creation_failed
171-
172-
env_creation_failed:
173-
DetailPrint "- ERROR: Environment creation failed"
174-
; Display an error message and exit
175-
${IfNot} ${Silent}
176-
MessageBox MB_OK "ERROR: Failed to create the Python environment. Installation will be aborted."
177-
${EndIf}
178-
Quit
102+
DetailPrint "Set up Python"
103+
CreateDirectory "$INSTDIR\python"
104+
ExecWait 'curl -s -o "$INSTDIR\python\python.zip" "https://www.python.org/ftp/python/3.10.9/python-3.10.9-embed-amd64.zip"'
105+
ExecWait 'tar -xf "$INSTDIR\python\python.zip" -C "$INSTDIR\python"'
106+
ExecWait 'curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py'
107+
ExecWait '$INSTDIR\python\python.exe get-pip.py --no-warn-script-location'
108+
109+
FileOpen $2 "$INSTDIR\python\python310._pth" a
110+
FileSeek $2 0 END
111+
FileWrite $2 "$\r$\nLib$\r$\n"
112+
FileWrite $2 "$\r$\nLib\site-packages$\r$\n"
113+
FileClose $2
179114

180-
install_lemonade:
181-
DetailPrint "-------------------------"
182-
DetailPrint "- Lemonade Installation -"
183-
DetailPrint "-------------------------"
115+
DetailPrint "-------------------------"
116+
DetailPrint "- Lemonade Installation -"
117+
DetailPrint "-------------------------"
184118

185119

186-
DetailPrint "- Installing $LEMONADE_SERVER_STRING..."
187-
${If} $HYBRID_SELECTED == "true"
188-
nsExec::ExecToLog '"$INSTDIR\$LEMONADE_CONDA_ENV\python.exe" -m pip install -e "$INSTDIR"[llm-oga-hybrid] --no-warn-script-location'
189-
${Else}
190-
nsExec::ExecToLog '"$INSTDIR\$LEMONADE_CONDA_ENV\python.exe" -m pip install -e "$INSTDIR"[llm] --no-warn-script-location'
191-
${EndIf}
192-
Pop $R0 ; Return value
193-
DetailPrint "- $LEMONADE_SERVER_STRING install return code: $R0"
120+
DetailPrint "- Installing $LEMONADE_SERVER_STRING..."
121+
${If} $HYBRID_SELECTED == "true"
122+
ExecWait '"$INSTDIR\python\python.exe" -m pip install "$INSTDIR"[llm-oga-hybrid] --no-warn-script-location' $8
123+
${Else}
124+
ExecWait '"$INSTDIR\python\python.exe" -m pip install "$INSTDIR"[llm] --no-warn-script-location' $8
125+
${EndIf}
126+
DetailPrint "- $LEMONADE_SERVER_STRING install return code: $8"
194127

195-
; Check if installation was successful (exit code should be 0)
196-
StrCmp $R0 0 install_success install_failed
128+
; Check if installation was successful (exit code should be 0)
129+
StrCmp $8 0 install_success install_failed
197130

198131
install_success:
199132
DetailPrint "- $LEMONADE_SERVER_STRING installation successful"
@@ -233,7 +166,7 @@ Section "Install Ryzen AI Hybrid Execution" HybridSec
233166
; Once we're done downloading and installing the archive the size comes out to about 370MB
234167
AddSize 388882
235168

236-
nsExec::ExecToLog 'conda run --no-capture-output -p $INSTDIR\$LEMONADE_CONDA_ENV lemonade-install --ryzenai hybrid -y'
169+
nsExec::ExecToLog '$INSTDIR\python\Scripts\lemonade-install --ryzenai hybrid -y'
237170

238171
Pop $R0 ; Return value
239172
DetailPrint "Hybrid execution mode install return code: $R0"
@@ -299,20 +232,19 @@ SubSection /e "Selected Models" ModelsSec
299232
${GetParameters} $CMDLINE
300233
${GetOptions} $CMDLINE "/Models=" $R0
301234
${If} $R0 != ""
302-
nsExec::ExecToLog 'conda run --no-capture-output -p $INSTDIR\$LEMONADE_CONDA_ENV lemonade-install --models $R0'
235+
nsExec::ExecToLog '$INSTDIR\python\Scripts\lemonade-install --models $R0'
303236
${Else}
304237
; Otherwise, only the default CPU model will be installed
305-
nsExec::ExecToLog 'conda run --no-capture-output -p $INSTDIR\$LEMONADE_CONDA_ENV lemonade-install --models Qwen2.5-0.5B-Instruct-CPU'
238+
nsExec::ExecToLog '$INSTDIR\python\Scripts\lemonade-install --models Qwen2.5-0.5B-Instruct-CPU'
306239
${EndIf}
307240
${Else}
308-
nsExec::ExecToLog 'conda run --no-capture-output -p $INSTDIR\$LEMONADE_CONDA_ENV lemonade-install --models $9'
241+
nsExec::ExecToLog '$INSTDIR\python\Scripts\lemonade-install --models $9'
309242
${EndIf}
310243
SectionEnd
311244

312245
SubSectionEnd
313246

314247
Section "-Add Desktop Shortcut" ShortcutSec
315-
; Create a desktop shortcut that passes the conda environment name as a parameter
316248
CreateShortcut "$DESKTOP\lemonade-server.lnk" "$INSTDIR\bin\lemonade-server.bat" "serve --keep-alive" "$INSTDIR\img\favicon.ico"
317249

318250
SectionEnd
@@ -458,7 +390,7 @@ LangString MUI_TEXT_ABORT_SUBTITLE "${LANG_ENGLISH}" "Installation has been abor
458390
LangString MUI_BUTTONTEXT_FINISH "${LANG_ENGLISH}" "Finish"
459391
LangString MUI_TEXT_LICENSE_TITLE ${LANG_ENGLISH} "AMD License Agreement"
460392
LangString MUI_TEXT_LICENSE_SUBTITLE ${LANG_ENGLISH} "Please review the license terms before installing AMD Ryzen AI Hybrid Execution Mode."
461-
LangString DESC_SEC01 ${LANG_ENGLISH} "The minimum set of dependencies for a lemonade server that runs LLMs on CPU."
393+
LangString DESC_SEC01 ${LANG_ENGLISH} "The minimum set of dependencies for a lemonade server that runs LLMs on CPU (includes Python)."
462394
LangString DESC_HybridSec ${LANG_ENGLISH} "Add support for running LLMs on Ryzen AI hybrid execution mode. Only available on Ryzen AI 300-series processors."
463395
LangString DESC_ModelsSec ${LANG_ENGLISH} "Select which models to install"
464396
LangString DESC_Qwen05Sec ${LANG_ENGLISH} "Small CPU-only Qwen model"
@@ -485,7 +417,6 @@ LangString DESC_DeepSeekQwen7BSec ${LANG_ENGLISH} "7B parameter DeepSeek Qwen mo
485417

486418
Function .onInit
487419
StrCpy $LEMONADE_SERVER_STRING "Lemonade Server"
488-
StrCpy $LEMONADE_CONDA_ENV "lemon_env"
489420
StrCpy $HYBRID_SELECTED "true"
490421

491422
; Create a variable to store selected models

installer/lemonade-server.bat

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@echo off
22
setlocal enabledelayedexpansion
3-
set CONDA_ENV=lemon_env
43

54
REM --keep-alive is only used by the bash script to make sure that, if the server fails to open, we don't close the terminal right away.
65
REM Check for --keep-alive argument and remove it from arguments passed to CLI
@@ -18,7 +17,7 @@ REM Change to parent directory where conda env and bin folders are located
1817
pushd "%~dp0.."
1918

2019
REM Run the Python CLI script through conda, passing filtered arguments
21-
call conda run --no-capture-output -p "%CD%\%CONDA_ENV%" lemonade-server-dev !ARGS!
20+
call "%CD%\python\Scripts\lemonade-server-dev" !ARGS!
2221
popd
2322

2423
REM Error handling: Show message and pause if --keep-alive was specified

installer/run_server.bat

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/lemonade/cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Keys:
6868
DTYPE = "dtype"
6969
PROMPT = "prompt"
7070
PROMPT_TOKENS = "prompt_tokens"
71+
PROMPT_TEMPLATE = "prompt_template"
7172
RESPONSE = "response"
7273
RESPONSE_TOKENS = "response_tokens"
7374
RESPONSE_LENGTHS_HISTOGRAM = "response_lengths_histogram"

src/lemonade/tools/ort_genai/oga.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,14 @@ def parser(add_help: bool = True) -> argparse.ArgumentParser:
330330
help="Download the model if needed, but don't load it",
331331
)
332332

333+
parser.add_argument(
334+
"--trust-remote-code",
335+
action="store_true",
336+
help="Set this flag to use models whose code is on the Hugging Face hub rather "
337+
"than natively in the OnnxRuntime Gen AI libraries. Please review the model code "
338+
"in advance as this is a security risk.",
339+
)
340+
333341
parser.add_argument(
334342
"--subfolder",
335343
default=None,
@@ -547,15 +555,28 @@ def _setup_npu_environment():
547555
return saved_state
548556

549557
@staticmethod
550-
def _load_model_and_setup_state(state, full_model_path, checkpoint):
558+
def _load_model_and_setup_state(
559+
state, full_model_path, checkpoint, trust_remote_code
560+
):
551561
"""
552562
Loads the OGA model from local folder and then loads the tokenizer.
553563
"""
554564
state.model = OrtGenaiModel(full_model_path)
555565

556-
hf_tokenizer = AutoTokenizer.from_pretrained(
557-
full_model_path, local_files_only=True
558-
)
566+
try:
567+
hf_tokenizer = AutoTokenizer.from_pretrained(
568+
full_model_path,
569+
local_files_only=True,
570+
trust_remote_code=trust_remote_code,
571+
)
572+
except ValueError as e:
573+
if "trust_remote_code" in str(e):
574+
raise ValueError(
575+
"This model requires you to execute code from the repo. Please review it "
576+
"and if you trust it, then use the `--trust-remote-code` flag with oga-load."
577+
)
578+
raise
579+
559580
state.tokenizer = OrtGenaiTokenizer(
560581
state.model.model,
561582
hf_tokenizer,
@@ -582,6 +603,7 @@ def run(
582603
int4_block_size: int = None,
583604
force: bool = False,
584605
download_only: bool = False,
606+
trust_remote_code=False,
585607
subfolder: str = None,
586608
) -> State:
587609
state.device = device
@@ -671,7 +693,9 @@ def run(
671693
"0" if "phi-" in checkpoint.lower() else "1"
672694
)
673695

674-
self._load_model_and_setup_state(state, full_model_path, checkpoint)
696+
self._load_model_and_setup_state(
697+
state, full_model_path, checkpoint, trust_remote_code
698+
)
675699
finally:
676700
self._cleanup_environment(saved_env_state)
677701

0 commit comments

Comments
 (0)