Skip to content

Feature: Support HuggingFace Text Generation including meta-llama2 model#266

Merged
kokokuo merged 4 commits into
developfrom
feature/huggingface-text-generation
Aug 3, 2023
Merged

Feature: Support HuggingFace Text Generation including meta-llama2 model#266
kokokuo merged 4 commits into
developfrom
feature/huggingface-text-generation

Conversation

@kokokuo
Copy link
Copy Markdown
Contributor

@kokokuo kokokuo commented Aug 2, 2023

Description

The Text Generation is one of the Natural Language Processing tasks supported by Hugging Face.

VulcanSQL supports the Using Text Generation by using the huggingface_text_generation filter. The result will be a string from huggingface_text_generation.

📢 Notice: The Text Generation default model is gpt2, If you would like to use the Meta LLama2 models, you have two method to do:

  1. Subscribe to the Pro Account.
  • Set the Meta LLama2 model using the model keyword argument in huggingface_text_generation, e.g: meta-llama/Llama-2-13b-chat-hf.
  1. Using Inference Endpoint.
  • Select one of the Meta LLama2 Models and deploy it to the Inference Endpoint.
  • Set the endpoint URL using the endpoint keyword argument in huggingface_text_generation.

Sample 1 - Subscribe to the Pro Account:

{% set data = [
  {
    "rank": 1,
    "institution": "Massachusetts Institute of Technology (MIT)",
    "location code":"US",
    "location":"United States"
  },
  {
    "rank": 2,
    "institution": "University of Cambridge",
    "location code":"UK",
    "location":"United Kingdom"
  },
  {
    "rank": 3,
    "institution": "Stanford University"
    "location code":"US",
    "location":"United States"
  }
  -- other universities.....
] %}

SELECT {{ data | huggingface_text_generation(query="Which university is the top-ranked university?", model="meta-llama/Llama-2-13b-chat-hf") }} as result

Sample 1 - Response:

[
  {
    "result": "Answer: Based on the provided list, the top-ranked university is Massachusetts Institute of Technology (MIT) with a rank of 1."
  }
]

Sample 2 - Using Inference Endpoint:

{% req universities %}
 SELECT rank,institution,"location code", "location" FROM read_csv_auto('2023-QS-World-University-Rankings.csv') 
{% endreq %}

SELECT {{ universities.value() | huggingface_text_generation(query="Which university located in the UK is ranked at the top of the list?", endpoint='xxx.yyy.zzz.huggingface.cloud') }} as result

Sample 2 - Response:

[
  {
    "result": "Answer: Based on the list provided, the top-ranked university in the UK is the University of Cambridge, which is ranked at number 2."
  }
]

Screenshot

SQL and API Schema
llama2-sample

Question 1 - Which university is the top-ranked university?
Question1

Question 2 - Which university located in the UK is ranked at the top of the list?
Question2

Additional Context

  • Refactor the original TableQuestionAnsweringFilter function logistic to keep simple and readable.
  • Support endpoint field for making users could use their HuggingFace Inference Endpoint when using huggingface_xxx filter.
  • Move the original request method to the request.ts and support try-catch to bypass the Axios error message.
  • Refactor for moving the sample data to test-data folder for reusing data and use describe.
  • Create model.ts to define the common type or const value.
  • Skip the test case of testing llama2 model, because using llama2 model needs to subscribe Pro Account and pay $9/month.

kokokuo added 2 commits July 31, 2023 18:06
- Add the "TextGenerationFilter".
- support huggingface filters could pass "endpoint" keyword arguments when using different filter task.
- add test cases of "TextGenerationFilter".
@vercel
Copy link
Copy Markdown

vercel Bot commented Aug 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vulcan-sql-document ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2023 2:25pm

@kokokuo kokokuo changed the title Feature: Support Huggingface Text Generation ( including llama2 model ) Feature: Support HuggingFace Text Generation including meta-llama2 model Aug 2, 2023
@kokokuo
Copy link
Copy Markdown
Contributor Author

kokokuo commented Aug 2, 2023

@cyyeh, Please assist me to check Document content - HuggingFace Text Generation, thanks!

Btw, I added the endpoint field in the Table Question Answering to support changing the API endpoint when using huggingface_xxxx filter.

Copy link
Copy Markdown
Contributor

@onlyjackfrost onlyjackfrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides some comments, others LGTM

if (!(typeof args === 'object') || !has(args, 'query'))
throw new InternalError('Must provide "query" keyword argument');
if (!args['query'])
throw new InternalError('The "query" argument must have value');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious about why we removed this query check.

Copy link
Copy Markdown
Contributor Author

@kokokuo kokokuo Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for asking the question. I added back the logistic for checking "query" has value or not with test cases in 5e22e51


Using the `huggingface_text_generation` filter. The result will be a string from `huggingface_text_generation`.

**Notice**: The **Text Generation** default model is **gpt2**, If you would like to use the [Meta LLama2](https://huggingface.co/meta-llama) models, you have two method to do:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If you would like to use the [Meta LLama2] models, you have two method to do"
Check the grammar.

Copy link
Copy Markdown
Contributor Author

@kokokuo kokokuo Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding the grammar issue, I have fixed the method to methods at 5e22e51

2. Select one of the [Meta LLama2](https://huggingface.co/meta-llama) Models and deploy it to the [Inference Endpoint](https://huggingface.co/inference-endpoints). Set the endpoint URL using the `endpoint` keyword argument in `huggingface_text_generation`.

```sql
SELECT {{ data | huggingface_text_generation(query="Which university is the top-ranked university?", endpoint='xxx.yyy.zzz.huggingface.cloud') }} as result
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can merge these to code snippet and use "comment" to describe the detail.
I think it will be more readable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the code snippet, the marked code is older code. After discussion with @onlyjackfrost and checking, no need to change.

HuggingFaceTableQuestionAnsweringFilterBuilder,
HuggingFaceTableQuestionAnsweringFilterRunner,
TextGenerationFilterBuilder,
TextGenerationFilterRunner,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure that the naming is aligned with HuggingFace, either by using it as a prefix or without it.

Copy link
Copy Markdown
Contributor Author

@kokokuo kokokuo Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding the naming issue, it has been fixed at 5e22e51

100 * 1000
);

// Skip the test case because the "meta-llama/Llama-2-13b-chat-hf" model need to upgrade your huggingface account to Pro Account by paying $9 per month
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any model that is free and can be used for testing?
If the structure of API response payload is the same, I think it could be used for testing.

Copy link
Copy Markdown
Contributor Author

@kokokuo kokokuo Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion, the free model has been added to the test cases and I renamed to Should not throw when passing the "query" argument by dynamic parameter through HuggingFace default recommended "gpt2" model 5e22e51

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Aug 2, 2023

Codecov Report

❌ Patch coverage is 80.76923% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.25%. Comparing base (180f8a6) to head (5e22e51).
⚠️ Report is 197 commits behind head on develop.

Files with missing lines Patch % Lines
...sion-huggingface/src/lib/filters/textGeneration.ts 85.71% 2 Missing and 2 partials ⚠️
...ges/extension-huggingface/src/lib/utils/request.ts 55.55% 4 Missing ⚠️
...gingface/src/lib/filters/tableQuestionAnswering.ts 81.81% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #266      +/-   ##
===========================================
- Coverage    90.25%   86.25%   -4.01%     
===========================================
  Files          346        8     -338     
  Lines         5931       80    -5851     
  Branches       794       19     -775     
===========================================
- Hits          5353       69    -5284     
+ Misses         421        7     -414     
+ Partials       157        4     -153     
Flag Coverage Δ
build ?
catalog-server ?
cli ?
core ?
extension-authenticator-canner ?
extension-dbt ?
extension-debug-tools ?
extension-driver-bq ?
extension-driver-canner ?
extension-driver-clickhouse ?
extension-driver-duckdb ?
extension-driver-ksqldb ?
extension-driver-pg ?
extension-driver-snowflake ?
extension-huggingface 86.25% <80.76%> (+0.53%) ⬆️
extension-store-canner ?
integration-testing ?
serve ?
test-utility ?

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…has value with test cases for huggingface filter

- fix grammar in README.
- fix the section of document .
- add logistic for checking query has value with test cases
Copy link
Copy Markdown
Contributor

@onlyjackfrost onlyjackfrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kokokuo kokokuo merged commit 5df01ae into develop Aug 3, 2023
@hanshino hanshino deleted the feature/huggingface-text-generation branch January 31, 2024 07:39
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