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

[GenAI] Introduce CausalLMPipelineChatClient for MEAI.IChatClient #7270

Merged
merged 7 commits into from
Nov 5, 2024

Conversation

LittleLittleCloud
Copy link
Contributor

@LittleLittleCloud LittleLittleCloud commented Oct 13, 2024

We are excited to review your PR.

So we can do the best job, please check:

  • There's a descriptive title that will make sense to other developers some time from now.
  • There's associated issues. All PR's should have issue(s) associated - unless a trivial self-evident change such as fixing a typo. You can use the format Fixes #nnnn in your description to cause GitHub to automatically close the issue(s) when your PR is merged.
  • Your change description explains what the change does, why you chose your approach, and anything else that reviewers should know.
  • You have included any necessary tests in the same PR.

This PR implements CausalLMPipelineChatClient<TTokenizer, TCausalLMModel> class for MEAI.IChatClient's intergration.

This PR also refactors the AutoGen and semantic kernel intergretion for Phi3, which pulls out the prompt template parts into an individual Phi3ChatTemplateBuilder class.

This PR also update STJ to 8.0.5 to address a security warning for that package

The CausalLMPipelineChatClient is used as the abstract class for all IChatClient implementation in GenAI models. For now, the following implementations are available

  • Phi3CausalLMChatClient
  • Llama3CausalLMChatClient

The MistralCausalLMChatClient will come in the following PR with additional support for tool call.

Usage

Checkout the MEAI folder under Microsoft.ML.GenAI.Samples` for examples. The following examples are added

  • Llama3_1
  • Phi3

Copy link

codecov bot commented Oct 13, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 152 lines in your changes missing coverage. Please review.

Project coverage is 68.84%. Comparing base (823fc17) to head (c5b9603).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...rosoft.ML.GenAI.Core/CausalLMPipelineChatClient.cs 0.00% 48 Missing ⚠️
...osoft.ML.GenAI.Phi/Phi3/Phi3ChatTemplateBuilder.cs 43.83% 35 Missing and 6 partials ⚠️
...crosoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs 0.00% 24 Missing ⚠️
...rosoft.ML.GenAI.Phi/Phi3/Phi3CausalLMChatClient.cs 0.00% 24 Missing ⚠️
...soft.ML.GenAI.LLaMA/Llama3_1ChatTemplateBuilder.cs 69.23% 5 Missing and 3 partials ⚠️
...c/Microsoft.ML.GenAI.Phi/Phi3/Phi3CausalLMAgent.cs 60.00% 6 Missing ⚠️
...enAI.Phi/Phi3/Phi3CausalLMChatCompletionService.cs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7270      +/-   ##
==========================================
+ Coverage   68.81%   68.84%   +0.03%     
==========================================
  Files        1461     1471      +10     
  Lines      272405   274124    +1719     
  Branches    28176    28411     +235     
==========================================
+ Hits       187442   188734    +1292     
- Misses      77727    78079     +352     
- Partials     7236     7311      +75     
Flag Coverage Δ
Debug 68.84% <33.33%> (+0.03%) ⬆️
production 63.30% <30.27%> (-0.01%) ⬇️
test 89.18% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...enAI.Phi/Phi3/Phi3CausalLMTextGenerationService.cs 35.71% <100.00%> (+1.56%) ⬆️
...st/Microsoft.ML.GenAI.LLaMA.Tests/LLaMA3_1Tests.cs 94.73% <100.00%> (+0.79%) ⬆️
...enAI.Phi/Phi3/Phi3CausalLMChatCompletionService.cs 61.90% <83.33%> (-3.10%) ⬇️
...c/Microsoft.ML.GenAI.Phi/Phi3/Phi3CausalLMAgent.cs 52.00% <60.00%> (-4.72%) ⬇️
...soft.ML.GenAI.LLaMA/Llama3_1ChatTemplateBuilder.cs 68.83% <69.23%> (+0.20%) ⬆️
...crosoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs 0.00% <0.00%> (ø)
...rosoft.ML.GenAI.Phi/Phi3/Phi3CausalLMChatClient.cs 0.00% <0.00%> (ø)
...osoft.ML.GenAI.Phi/Phi3/Phi3ChatTemplateBuilder.cs 43.83% <43.83%> (ø)
...rosoft.ML.GenAI.Core/CausalLMPipelineChatClient.cs 0.00% <0.00%> (ø)

... and 29 files with indirect coverage changes

@LittleLittleCloud LittleLittleCloud mentioned this pull request Oct 7, 2024
13 tasks
@michaelgsharp
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@LittleLittleCloud LittleLittleCloud merged commit 3659a48 into dotnet:main Nov 5, 2024
25 checks passed
@michaelgsharp
Copy link
Member

/backport to release/4.0

Copy link

github-actions bot commented Nov 8, 2024

Started backporting to release/4.0: https://github.com/dotnet/machinelearning/actions/runs/11749726947

Copy link

github-actions bot commented Nov 8, 2024

@michaelgsharp backporting to release/4.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: leverage MEAI abstraction
Applying: Update src/Microsoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs
Applying: Update src/Microsoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs
Applying: Update src/Microsoft.ML.GenAI.Phi/Phi3/Phi3CausalLMChatClient.cs
Applying: fix comments
Using index info to reconstruct a base tree...
M	src/Microsoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs
M	src/Microsoft.ML.GenAI.Phi/Phi3/Phi3CausalLMChatClient.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Microsoft.ML.GenAI.Phi/Phi3/Phi3CausalLMChatClient.cs
Auto-merging src/Microsoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs
CONFLICT (content): Merge conflict in src/Microsoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0005 fix comments
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link

github-actions bot commented Nov 8, 2024

@michaelgsharp an error occurred while backporting to release/4.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

michaelgsharp pushed a commit to michaelgsharp/machinelearning that referenced this pull request Nov 11, 2024
…tnet#7270)

* leverage MEAI abstraction

* Update src/Microsoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>

* Update src/Microsoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>

* Update src/Microsoft.ML.GenAI.Phi/Phi3/Phi3CausalLMChatClient.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>

* fix comments

* Update Microsoft.ML.GenAI.Core.csproj

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
michaelgsharp added a commit that referenced this pull request Nov 11, 2024
) (#7298)

* leverage MEAI abstraction

* Update src/Microsoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs



* Update src/Microsoft.ML.GenAI.LLaMA/Llama3CausalLMChatClient.cs



* Update src/Microsoft.ML.GenAI.Phi/Phi3/Phi3CausalLMChatClient.cs



* fix comments

* Update Microsoft.ML.GenAI.Core.csproj

---------

Co-authored-by: Xiaoyun Zhang <xiaoyuz@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants