Skip to content

Commit 225957d

Browse files
ltoniazziamakropoulos
authored andcommitted
Point to gguf format for lora
1 parent f99ee2f commit 225957d

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public class MyScript : MonoBehaviour
248248
// Otherwise the model file can be copied directly inside the StreamingAssets folder.
249249
llm.SetModel("Phi-3-mini-4k-instruct-q4.gguf");
250250
// optional: you can also set a lora in a similar fashion
251-
llm.SetLora("my-lora.bin");
251+
llm.SetLora("my-lora.gguf");
252252
// optional: you can set the chat template of the model if it is not correctly identified
253253
// You can find a list of chat templates in the ChatTemplate.templates.Keys
254254
llm.SetTemplate("phi-3");
@@ -374,8 +374,8 @@ If the user's GPU is not supported, the LLM will fall back to the CPU
374374

375375
- <details><summary>Advanced options</summary>
376376

377-
- `Download lora` click to download a LoRA model in .bin format
378-
- `Load lora` click to load a LoRA model in .bin format
377+
- `Download lora` click to download a LoRA model in .gguf format
378+
- `Load lora` click to load a LoRA model in .gguf format
379379
- <details><summary><code>Context Size</code> size of the prompt context (0 = context size of the model)</summary> This is the number of tokens the model can take as input when generating responses. Higher values use more RAM or VRAM (if using GPU). </details>
380380
- `Batch Size` batch size for prompt processing (default: 512)
381381
- `Model` the path of the model being used (relative to the Assets/StreamingAssets folder)

Runtime/LLM.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public LLMException(string message, int errorCode) : base(message)
2222
}
2323
}
2424

25-
public class DestroyException : Exception {}
25+
public class DestroyException : Exception { }
2626
/// \endcond
2727

2828
[DefaultExecutionOrder(-1)]
@@ -72,7 +72,7 @@ public class LLM : MonoBehaviour
7272
/// <summary> Chat template used for the model </summary>
7373
[ModelAdvanced] public string chatTemplate = ChatTemplate.DefaultTemplate;
7474
/// <summary> the paths of the LORA models being used (relative to the Assets/StreamingAssets folder).
75-
/// Models with .bin format are allowed.</summary>
75+
/// Models with .gguf format are allowed.</summary>
7676
[ModelAdvanced] public string lora = "";
7777

7878
/// \cond HIDE
@@ -192,9 +192,9 @@ public void SetModel(string path)
192192
/// <summary>
193193
/// Allows to set a LORA model to use in the LLM.
194194
/// The model provided is copied to the Assets/StreamingAssets folder that allows it to also work in the build.
195-
/// Models supported are in .bin format.
195+
/// Models supported are in .gguf format.
196196
/// </summary>
197-
/// <param name="path">path to LORA model to use (.bin format)</param>
197+
/// <param name="path">path to LORA model to use (.gguf format)</param>
198198
public void SetLora(string path)
199199
{
200200
lora = "";
@@ -204,9 +204,9 @@ public void SetLora(string path)
204204
/// <summary>
205205
/// Allows to add a LORA model to use in the LLM.
206206
/// The model provided is copied to the Assets/StreamingAssets folder that allows it to also work in the build.
207-
/// Models supported are in .bin format.
207+
/// Models supported are in .gguf format.
208208
/// </summary>
209-
/// <param name="path">path to LORA model to use (.bin format)</param>
209+
/// <param name="path">path to LORA model to use (.gguf format)</param>
210210
public void AddLora(string path)
211211
{
212212
string loraPath = GetModelLoraPath(path, true);
@@ -220,9 +220,9 @@ public void AddLora(string path)
220220

221221
/// <summary>
222222
/// Allows to remove a LORA model from the LLM.
223-
/// Models supported are in .bin format.
223+
/// Models supported are in .gguf format.
224224
/// </summary>
225-
/// <param name="path">path to LORA model to remove (.bin format)</param>
225+
/// <param name="path">path to LORA model to remove (.gguf format)</param>
226226
public void RemoveLora(string path)
227227
{
228228
string loraPath = GetModelLoraPath(path, true);
@@ -373,7 +373,7 @@ void CallIfNotDestroyed(EmptyCallback fn)
373373
private void InitService(string arguments)
374374
{
375375
if (debug) CallIfNotDestroyed(() => SetupLogging());
376-
CallIfNotDestroyed(() => {LLMObject = llmlib.LLM_Construct(arguments);});
376+
CallIfNotDestroyed(() => { LLMObject = llmlib.LLM_Construct(arguments); });
377377
if (remote) CallIfNotDestroyed(() => llmlib.LLM_StartServer(LLMObject));
378378
CallIfNotDestroyed(() => llmlib.LLM_SetTemplate(LLMObject, chatTemplate));
379379
CallIfNotDestroyed(() => CheckLLMStatus(false));
@@ -383,7 +383,7 @@ private void StartService()
383383
{
384384
llmThread = new Thread(() => llmlib.LLM_Start(LLMObject));
385385
llmThread.Start();
386-
while (!llmlib.LLM_Started(LLMObject)) {}
386+
while (!llmlib.LLM_Started(LLMObject)) { }
387387
loraWeights = new List<float>();
388388
for (int i = 0; i < lora.Split(" ").Count(); i++) loraWeights.Add(1f);
389389
started = true;
@@ -446,7 +446,7 @@ void AssertStarted()
446446

447447
void CheckLLMStatus(bool log = true)
448448
{
449-
if (llmlib == null) {return;}
449+
if (llmlib == null) { return; }
450450
IntPtr stringWrapper = llmlib.StringWrapper_Construct();
451451
int status = llmlib.LLM_Status(LLMObject, stringWrapper);
452452
string result = llmlib.GetStringWrapperResult(stringWrapper);
@@ -553,7 +553,7 @@ public async Task<string> SetLoraScale(string loraToScale, float scale)
553553
loraWeightRequest.loraWeights = new List<LoraWeightRequest>();
554554
for (int i = 0; i < loraWeights.Count; i++)
555555
{
556-
loraWeightRequest.loraWeights.Add(new LoraWeightRequest() {id = i, scale = loraWeights[i]});
556+
loraWeightRequest.loraWeights.Add(new LoraWeightRequest() { id = i, scale = loraWeights[i] });
557557
}
558558
;
559559

@@ -607,7 +607,7 @@ public async Task<string> Slot(string json)
607607
public async Task<string> Completion(string json, Callback<string> streamCallback = null)
608608
{
609609
AssertStarted();
610-
if (streamCallback == null) streamCallback = (string s) => {};
610+
if (streamCallback == null) streamCallback = (string s) => { };
611611
StreamWrapper streamWrapper = ConstructStreamWrapper(streamCallback);
612612
await Task.Run(() => llmlib.LLM_Completion(LLMObject, json, streamWrapper.GetStringWrapper()));
613613
if (!started) return null;
@@ -621,7 +621,7 @@ public async Task<string> Completion(string json, Callback<string> streamCallbac
621621
public async Task SetBasePrompt(string base_prompt)
622622
{
623623
AssertStarted();
624-
SystemPromptRequest request = new SystemPromptRequest(){system_prompt = base_prompt, prompt = " ", n_predict = 0};
624+
SystemPromptRequest request = new SystemPromptRequest() { system_prompt = base_prompt, prompt = " ", n_predict = 0 };
625625
await Completion(JsonUtility.ToJson(request));
626626
}
627627

0 commit comments

Comments
 (0)