-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[GenAI] Add LLaMA support #7220
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
Merged
LittleLittleCloud
merged 25 commits into
dotnet:main
from
LittleLittleCloud:u/xiaoyun/AddLLaMA
Aug 28, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7b17731
add llama
LittleLittleCloud 996548b
add test for tokenizer
LittleLittleCloud 023c9f7
make llama 3.1 working
LittleLittleCloud 63be655
update
LittleLittleCloud 44b3302
add shape test for 70b and 405b
LittleLittleCloud 3d4482d
clean up
LittleLittleCloud d3681dd
Merge branch 'u/xiaoyun/AddLLaMA' of https://github.com/LittleLittleC…
LittleLittleCloud c77b518
add tests
LittleLittleCloud 6498e2e
update
LittleLittleCloud 6557eac
fix error
LittleLittleCloud fd61cff
calculate rotary embedding in model layer
LittleLittleCloud a3f2e41
remove rotary_emb from attention
LittleLittleCloud 9a03acc
update feed
LittleLittleCloud 0542bf7
update .csproj
LittleLittleCloud 485f9af
Update NuGet.config
LittleLittleCloud 896a21b
fix test
LittleLittleCloud d3d5b61
pass device
LittleLittleCloud d161b49
fix test
LittleLittleCloud 32b74e3
update constructor
LittleLittleCloud b2b155c
disable 405b test
LittleLittleCloud 2b48080
update
LittleLittleCloud e0ba719
disable 70b test
LittleLittleCloud 093a38e
use windows only fact
LittleLittleCloud 51bdcc6
revert change
LittleLittleCloud 19a2d7e
rename test to LLaMA3_1
LittleLittleCloud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.