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

Added how settings impact generation to the readme #49

Merged
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
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@ obj/
obj.meta
bin/
bin.meta
LLMUnity.csproj.meta
hooks.meta
hooks/pre-commit.meta
setup.sh.meta
*.api
*.api.meta
CHANGELOG.release.md.meta

7 changes: 7 additions & 0 deletions CHANGELOG.release.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions LLMUnity.csproj.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
39 changes: 21 additions & 18 deletions Runtime/LLMUnitySetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static void makeExecutable(string path)
public static async Task DownloadFile(
string fileUrl, string savePath, bool executable = false,
TaskCallback<string> callback = null, Callback<float> progresscallback = null,
int chunkSize = 1024 * 1024)
long chunkSize = 10 * 1024 * 1024)
{
// download a file to the specified path
if (File.Exists(savePath))
Expand All @@ -100,34 +100,37 @@ public static async Task DownloadFile(
throw new System.Exception("Failed to get file size. Error: " + www.error);

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))
{
for (long i = 0; i < fileSize; i += chunkSize)
long chunks = (long) Mathf.Ceil((float)fileSize / chunkSize);
for (long i = 0; i < chunks; i++)
{
long startByte = i;
long endByte = (long)Mathf.Min(i + chunkSize - 1, fileSize - 1);
long startByte = i * chunkSize;
long endByte = startByte + chunkSize - 1;
if (endByte > fileSize - 1) endByte = fileSize - 1;

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

asyncOperation = www.SendWebRequest();
asyncOperation = wwwChunk.SendWebRequest();

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

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

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

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

Expand Down
8 changes: 8 additions & 0 deletions hooks.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions hooks/pre-commit.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions setup.sh.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading