Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.0.4 #50

Merged
merged 7 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## v1.0.4
#### 🐛 Fixes

- Fix download function (PR: #51)

#### 📦 General

- Added how settings impact generation to the readme (PR: #49)


## v1.0.3
#### 🐛 Fixes

Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.release.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### 🐛 Fixes

- fix slash in windows paths (PR: #42)
- Fix chmod when deploying from windows (PR: #43)
- Fix download function (PR: #51)

### 📦 General

- Added how settings impact generation to the readme (PR: #49)

14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ If it is not selected, the full reply from the model is received in one go
- `Model` the model being used (inside the Assets/StreamingAssets folder)
- `Lora` the LORA model being used (inside the Assets/StreamingAssets folder)
- Advanced options:
- `Context Size` Size of the prompt context (0 = context size of the model)
- `Batch Size` Batch size for prompt processing (default: 512)
- `Seed` seed for reproducibility. For random results every time select -1
- `Temperature` LLM temperature, lower values give more deterministic answers
- `Top K` top-k sampling (default: 40, 0 = disabled)
- `Top P` top-p sampling (default: 0.9, 1.0 = disabled)
- `Num Predict` number of tokens to predict (default: 256, -1 = infinity, -2 = until context filled)
- <code>Context Size</code> Size of the prompt context (0 = context size of the model)
- <code>Batch Size</code> Batch size for prompt processing (default: 512)
- <code>Seed</code> seed for reproducibility. For random results every time select -1
- <details><summary><code>Temperature</code> LLM temperature, lower values give more deterministic answers</summary>The temperature setting adjusts how random the generated responses are. Turning it up makes the generated choices more varied and unpredictable. Turning it down makes the generated responses more predictable and focused on the most likely options.</details>
- <details><summary><code>Top K</code> top-k sampling (default: 40, 0 = disabled)</summary>The top k value controls the top k most probable tokens at each step of generation. This value can help fine tune the output and make this adhere to specific patterns or constraints.</details>
- <details><summary><code>Top P</code> top-p sampling (default: 0.9, 1.0 = disabled)</summary>The top p value controls the cumulative probability of generated tokens. The model will generate tokens until this theshold (p) is reached. By lowering this value you can shorten output & encourage / discourage more diverse output.</details>
- <details><summary><code>Num Predict</code> number of tokens to predict (default: 256, -1 = infinity, -2 = until context filled)</summary>This is the amount of tokens the model will maximum predict. When N predict is reached the model will stop generating. This means words / sentences might not get finished if this is too low. </details>

#### :left_speech_bubble: Chat Settings
- `Player Name` the name of the player
Expand Down
2 changes: 1 addition & 1 deletion Runtime/LLM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static async Task SetupBinaries()
binariesDone += 1;
if (!File.Exists(server))
{
string serverZip = Path.Combine(Application.dataPath, "llamafile.zip");
string serverZip = Path.Combine(Application.temporaryCachePath, "llamafile.zip");
if (!File.Exists(serverZip)) await LLMUnitySetup.DownloadFile(serverZipUrl, serverZip, false, null, SetBinariesProgress);
binariesDone += 1;
LLMUnitySetup.ExtractZip(serverZip, GetAssetPath());
Expand Down
76 changes: 27 additions & 49 deletions Runtime/LLMUnitySetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Diagnostics;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
using Debug = UnityEngine.Debug;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO.Compression;
using System.Net;

namespace LLMUnity
{
Expand Down Expand Up @@ -74,10 +74,24 @@ public static void makeExecutable(string path)
}

#if UNITY_EDITOR
public class DownloadStatus
{
Callback<float> progresscallback;

public DownloadStatus(Callback<float> progresscallback = null)
{
this.progresscallback = progresscallback;
}

public void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progresscallback?.Invoke(e.ProgressPercentage / 100.0f);
}
}

public static async Task DownloadFile(
string fileUrl, string savePath, bool executable = false,
TaskCallback<string> callback = null, Callback<float> progresscallback = null,
long chunkSize = 10 * 1024 * 1024)
TaskCallback<string> callback = null, Callback<float> progresscallback = null)
{
// download a file to the specified path
if (File.Exists(savePath))
Expand All @@ -87,59 +101,23 @@ public static async Task DownloadFile(
else
{
Debug.Log($"Downloading {fileUrl}...");
string tmpPath = Path.Combine(Application.temporaryCachePath, Path.GetFileName(savePath));

UnityWebRequest www = UnityWebRequest.Head(fileUrl);
UnityWebRequestAsyncOperation asyncOperation = www.SendWebRequest();

while (!asyncOperation.isDone)
{
await Task.Delay(100); // Adjust the delay as needed
}

if (www.result != UnityWebRequest.Result.Success)
throw new System.Exception("Failed to get file size. Error: " + www.error);
WebClient client = new WebClient();
DownloadStatus downloadStatus = new DownloadStatus(progresscallback);
client.DownloadProgressChanged += downloadStatus.DownloadProgressChanged;
await client.DownloadFileTaskAsync(fileUrl, tmpPath);
if (executable) makeExecutable(tmpPath);

long fileSize = long.Parse(www.GetResponseHeader("Content-Length"));
AssetDatabase.StartAssetEditing();
Directory.CreateDirectory(Path.GetDirectoryName(savePath));
using (FileStream fs = new FileStream(savePath, FileMode.Create, FileAccess.Write))
{
long chunks = (long) Mathf.Ceil((float)fileSize / chunkSize);
for (long i = 0; i < chunks; i++)
{
long startByte = i * chunkSize;
long endByte = startByte + chunkSize - 1;
if (endByte > fileSize - 1) endByte = fileSize - 1;

using (UnityWebRequest wwwChunk = UnityWebRequest.Get(fileUrl))
{
wwwChunk.SetRequestHeader("Range", "bytes=" + startByte + "-" + endByte);

asyncOperation = wwwChunk.SendWebRequest();

while (!asyncOperation.isDone)
{
await Task.Delay(1000); // Adjust the delay as needed
}

if (wwwChunk.result != UnityWebRequest.Result.Success)
throw new System.Exception("Download failed. Error: " + wwwChunk.error);

fs.Write(wwwChunk.downloadHandler.data, 0, wwwChunk.downloadHandler.data.Length);

int progressPercentage = Mathf.FloorToInt((float) i / chunks * 100);
if (progressPercentage % 1 == 0)
progresscallback((float)progressPercentage / 100);
}
}
}

if (executable) makeExecutable(savePath);
File.Move(tmpPath, savePath);
AssetDatabase.StopAssetEditing();
Debug.Log($"Download complete!");

progresscallback?.Invoke(1f);
callback?.Invoke(savePath);
}
progresscallback(1f);
callback?.Invoke(savePath);
}

public static async Task<string> AddAsset(string assetPath, string basePath)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.3
v1.0.4
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "ai.undream.llmunity",
"version": "1.0.3",
"version": "1.0.4",
"displayName": "LLMUnity",
"description": "LLMUnity allows to run and distribute LLM models in the Unity engine.",
"unity": "2022.3",
"unityRelease": "16f1",
"documentationUrl": "https://github.com/amakropoulos/LLMUnity",
"documentationUrl": "https://github.com/undreamai/LLMUnity",
"keywords": [
"llm",
"large language model",
Expand Down
Loading