Skip to content

Commit 84bb5a3

Browse files
authored
Merge pull request #702 from martindevans/interruptible_async_model_load
Interruptible Async Model Loading With Progress Monitoring
2 parents b47ed92 + 1ec0fee commit 84bb5a3

25 files changed

+135
-29
lines changed

LLama.Examples/Examples/BatchedExecutorFork.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static async Task Run()
1919
string modelPath = UserSettings.GetModelPath();
2020

2121
var parameters = new ModelParams(modelPath);
22-
using var model = LLamaWeights.LoadFromFile(parameters);
22+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
2323

2424
var prompt = AnsiConsole.Ask("Prompt (or ENTER for default):", "Not many people know that");
2525

LLama.Examples/Examples/BatchedExecutorGuidance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static async Task Run()
1919
string modelPath = UserSettings.GetModelPath();
2020

2121
var parameters = new ModelParams(modelPath);
22-
using var model = LLamaWeights.LoadFromFile(parameters);
22+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
2323

2424
var positivePrompt = AnsiConsole.Ask("Positive Prompt (or ENTER for default):", "My favourite colour is").Trim();
2525
var negativePrompt = AnsiConsole.Ask("Negative Prompt (or ENTER for default):", "I hate the colour red. My favourite colour is").Trim();

LLama.Examples/Examples/BatchedExecutorRewind.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static async Task Run()
2020
string modelPath = UserSettings.GetModelPath();
2121

2222
var parameters = new ModelParams(modelPath);
23-
using var model = LLamaWeights.LoadFromFile(parameters);
23+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
2424

2525
var prompt = AnsiConsole.Ask("Prompt (or ENTER for default):", "Not many people know that");
2626

LLama.Examples/Examples/BatchedExecutorSaveAndLoad.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static async Task Run()
1818
string modelPath = UserSettings.GetModelPath();
1919

2020
var parameters = new ModelParams(modelPath);
21-
using var model = LLamaWeights.LoadFromFile(parameters);
21+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
2222

2323
var prompt = AnsiConsole.Ask("Prompt (or ENTER for default):", "Not many people know that");
2424

LLama.Examples/Examples/ChatChineseGB2312.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static async Task Run()
3131
GpuLayerCount = 5,
3232
Encoding = Encoding.UTF8
3333
};
34-
using var model = LLamaWeights.LoadFromFile(parameters);
34+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
3535
using var context = model.CreateContext(parameters);
3636
var executor = new InteractiveExecutor(context);
3737

LLama.Examples/Examples/ChatSessionStripRoleName.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public static async Task Run()
1515
Seed = 1337,
1616
GpuLayerCount = 5
1717
};
18-
using var model = LLamaWeights.LoadFromFile(parameters);
18+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
1919
using var context = model.CreateContext(parameters);
2020
var executor = new InteractiveExecutor(context);
2121

22-
var chatHistoryJson = File.ReadAllText("Assets/chat-with-bob.json");
22+
var chatHistoryJson = await File.ReadAllTextAsync("Assets/chat-with-bob.json");
2323
ChatHistory chatHistory = ChatHistory.FromJson(chatHistoryJson) ?? new ChatHistory();
2424

2525
ChatSession session = new(executor, chatHistory);

LLama.Examples/Examples/ChatSessionWithHistory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static async Task Run()
1313
Seed = 1337,
1414
GpuLayerCount = 5
1515
};
16-
using var model = LLamaWeights.LoadFromFile(parameters);
16+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
1717
using var context = model.CreateContext(parameters);
1818
var executor = new InteractiveExecutor(context);
1919

LLama.Examples/Examples/ChatSessionWithRestart.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public static async Task Run()
1313
Seed = 1337,
1414
GpuLayerCount = 5
1515
};
16-
using var model = LLamaWeights.LoadFromFile(parameters);
16+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
1717
using var context = model.CreateContext(parameters);
1818
var executor = new InteractiveExecutor(context);
1919

20-
var chatHistoryJson = File.ReadAllText("Assets/chat-with-bob.json");
20+
var chatHistoryJson = await File.ReadAllTextAsync("Assets/chat-with-bob.json");
2121
ChatHistory chatHistory = ChatHistory.FromJson(chatHistoryJson) ?? new ChatHistory();
2222
ChatSession prototypeSession =
2323
await ChatSession.InitializeSessionFromHistoryAsync(executor, chatHistory);

LLama.Examples/Examples/ChatSessionWithRoleName.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public static async Task Run()
1313
Seed = 1337,
1414
GpuLayerCount = 5
1515
};
16-
using var model = LLamaWeights.LoadFromFile(parameters);
16+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
1717
using var context = model.CreateContext(parameters);
1818
var executor = new InteractiveExecutor(context);
1919

20-
var chatHistoryJson = File.ReadAllText("Assets/chat-with-bob.json");
20+
var chatHistoryJson = await File.ReadAllTextAsync("Assets/chat-with-bob.json");
2121
ChatHistory chatHistory = ChatHistory.FromJson(chatHistoryJson) ?? new ChatHistory();
2222

2323
ChatSession session = new(executor, chatHistory);

LLama.Examples/Examples/CodingAssistant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static async Task Run()
2929
{
3030
ContextSize = 4096
3131
};
32-
using var model = LLamaWeights.LoadFromFile(parameters);
32+
using var model = await LLamaWeights.LoadFromFileAsync(parameters);
3333
using var context = model.CreateContext(parameters);
3434
var executor = new InstructExecutor(context, InstructionPrefix, InstructionSuffix, null);
3535

0 commit comments

Comments
 (0)