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

FastAPI Framework Setup #7

Closed
wants to merge 1 commit into from

Conversation

XXXJumpingFrogXXX
Copy link

This PR includes the following changes:
(1) Created the latest main.py file and completed some basic FastAPI settings in it.
(2) Renamed the original main.py file to original_main.py.
(3) Kept the existing piggy directory and created a chat directory to establish separate routers and APIs for each project.

@@ -0,0 +1,110 @@
from fastapi import APIRouter
Copy link
Member

Choose a reason for hiding this comment

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

This is imported but unused.

Copy link
Author

@XXXJumpingFrogXXX XXXJumpingFrogXXX Oct 21, 2024

Choose a reason for hiding this comment

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

I modified the code in PR # 9. This is used in the new code now and essential for fastapi part.

Comment on lines +28 to +58
llama_model, llama_tokenizer = FastLanguageModel.from_pretrained(
model_name = "Antonio27/llama3-8b-4-bit-for-sugar",
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
)

gemma_model, gemma_tokenizer = FastLanguageModel.from_pretrained(
model_name = "unsloth/gemma-2-9b-it-bnb-4bit",
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
)

FastLanguageModel.for_inference(llama_model)
llama_tokenizer.pad_token = llama_tokenizer.eos_token
llama_tokenizer.add_eos_token = True

inputs = llama_tokenizer(
[
alpaca_prompt.format(
f'''
Your task is to answer children's questions using simple language.
Explain any difficult words in a way a 3-year-old can understand.
Keep responses under 60 words.
\n\nQuestion: {value.query}
''', # instruction
"", # input
"", # output - leave this blank for generation!
)
], return_tensors="pt").to("cuda")
Copy link
Member

Choose a reason for hiding this comment

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

These should be assigned once and used whenever as it seems their params won't change after the first assignment, there's no reason to reassign them whenever the function is called.

class Question(BaseModel):
query: str

@router.post("/generate_answer")
Copy link
Member

Choose a reason for hiding this comment

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

router doesn't exist yet, how come you're using it?

Copy link
Author

Choose a reason for hiding this comment

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

Here's the above question. I have modified that.

@chimosky
Copy link
Member

chimosky commented Oct 13, 2024

Reviewed ce06570, your commit message should be improved to explain what exactly we're doing with FastAPI and why.

The header is just a summary, your change needs more than a summary.

Also, please avoid opening PRs with your master branch, checkout our contributing docs.

@XXXJumpingFrogXXX
Copy link
Author

Reviewed ce06570, your commit message should be improved to explain what exactly we're doing with FastAPI and why.

The header is just a summary, your change needs more than a summary.

Also, please avoid opening PRs with your master branch, checkout our contributing docs.

I agree. I make a detailed introduction in the new PR #9

@XXXJumpingFrogXXX
Copy link
Author

I made the latest modifications in PR #9 and provided a detailed introduction, so I will close this PR.

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.

2 participants