-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add llama * add test for tokenizer * make llama 3.1 working * update * add shape test for 70b and 405b * clean up * add tests * update * fix error * calculate rotary embedding in model layer * remove rotary_emb from attention * update feed * update .csproj * Update NuGet.config * fix test * pass device * fix test * update constructor * disable 405b test * update * disable 70b test * use windows only fact * revert change * rename test to LLaMA3_1
- Loading branch information
1 parent
fa8c822
commit 70e5ab1
Showing
57 changed files
with
3,932 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using AutoGen.Core; | ||
using Microsoft.ML.GenAI.Core; | ||
using Microsoft.ML.GenAI.Core.Extension; | ||
using Microsoft.ML.GenAI.LLaMA; | ||
using Microsoft.ML.Tokenizers; | ||
using TorchSharp; | ||
using static TorchSharp.torch; | ||
|
||
namespace Microsoft.ML.GenAI.Samples.Llama; | ||
|
||
internal class LlamaSample | ||
{ | ||
public static async void Run() | ||
{ | ||
var device = "cuda"; | ||
if (device == "cuda") | ||
{ | ||
torch.InitializeDeviceType(DeviceType.CUDA); | ||
} | ||
|
||
var defaultType = ScalarType.Float16; | ||
torch.manual_seed(1); | ||
torch.set_default_dtype(defaultType); | ||
var weightFolder = @"C:\Users\xiaoyuz\source\repos\Meta-Llama-3.1-8B-Instruct"; | ||
var configName = "config.json"; | ||
var originalWeightFolder = Path.Combine(weightFolder, "original"); | ||
|
||
Console.WriteLine("Loading Llama from huggingface model weight folder"); | ||
var stopWatch = System.Diagnostics.Stopwatch.StartNew(); | ||
stopWatch.Start(); | ||
var tokenizer = LlamaTokenizerHelper.FromPretrained(originalWeightFolder); | ||
var model = LlamaForCausalLM.FromPretrained(weightFolder, configName, layersOnTargetDevice: -1); | ||
|
||
var pipeline = new CausalLMPipeline<TiktokenTokenizer, LlamaForCausalLM>(tokenizer, model, device); | ||
|
||
var agent = new LlamaCausalLMAgent(pipeline, "assistant") | ||
.RegisterPrintMessage(); | ||
|
||
var task = """ | ||
Write a C# program to print the sum of two numbers. Use top-level statement, put code between ```csharp and ```. | ||
"""; | ||
|
||
await agent.SendAsync(task); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.