From 26935aa1b5c9f456b5e00fe10f67c14334a11297 Mon Sep 17 00:00:00 2001 From: ModelHub XC Date: Tue, 1 Sep 2026 12:26:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=EF=BC=8C=E7=94=B1ModelHub=20XC=E7=A4=BE=E5=8C=BA=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Model: Svngoku/Llama-3.1-8B-AlpaCare-MedInstruct-GGUF Source: Original Platform --- .gitattributes | 39 +++++++++ README.md | 208 ++++++++++++++++++++++++++++++++++++++++++++ config.json | 3 + unsloth.F16.gguf | 3 + unsloth.Q4_K_M.gguf | 3 + unsloth.Q5_K_M.gguf | 3 + unsloth.Q8_0.gguf | 3 + 7 files changed, 262 insertions(+) create mode 100644 .gitattributes create mode 100644 README.md create mode 100644 config.json create mode 100644 unsloth.F16.gguf create mode 100644 unsloth.Q4_K_M.gguf create mode 100644 unsloth.Q5_K_M.gguf create mode 100644 unsloth.Q8_0.gguf diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b91ffab --- /dev/null +++ b/.gitattributes @@ -0,0 +1,39 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text +unsloth.F16.gguf filter=lfs diff=lfs merge=lfs -text +unsloth.Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text +unsloth.Q8_0.gguf filter=lfs diff=lfs merge=lfs -text +unsloth.Q5_K_M.gguf filter=lfs diff=lfs merge=lfs -text diff --git a/README.md b/README.md new file mode 100644 index 0000000..f081bb9 --- /dev/null +++ b/README.md @@ -0,0 +1,208 @@ +--- +base_model: unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit +language: +- en +- fr +- de +- hi +- it +- pt +- es +- th +license: apache-2.0 +tags: +- text-generation-inference +- transformers +- unsloth +- llama +- trl +datasets: +- lavita/AlpaCare-MedInstruct-52k +metrics: +- accuracy +model-index: +- name: Llama-3.1-8B-AlpaCare-MedInstruct + results: + - task: + type: text-generation + dataset: + name: GEval + type: GEval + metrics: + - name: Medical Q&A + type: Medical Q&A 20 shots + value: 70 +pipeline_tag: text-generation +--- + +# Llama-3.1-8B AlpaCare MediInstruct + + + +- **Developed by:** Svngoku +- **License:** apache-2.0 +- **Finetuned from model :** `unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit` +- **Max Context Windows :** `4096` +- **Function Calling :** The model support `Function calling` +- **Capacity :** Real-time and batch inference + +## Inference with Unsloth + +```py +max_seq_length = 4096 +dtype = None +load_in_4bit = True # Use 4bit quantization to reduce memory usage. + +alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. + +### Instruction: +{} + +### Input: +{} + +### Response: +{}""" +``` + + +```py +from unsloth import FastLanguageModel +model, tokenizer = FastLanguageModel.from_pretrained( + model_name = "Svngoku/Llama-3.1-8B-AlpaCare-MedInstruct", + max_seq_length = max_seq_length, + dtype = dtype, + load_in_4bit = load_in_4bit, +) +FastLanguageModel.for_inference(model) +``` + +```py +def generate_medical_answer(input: str = "", instruction: str = ""): + inputs = tokenizer( + [ + alpaca_prompt.format( + instruction, + input, + "", + ) + ], return_tensors = "pt").to("cuda") + text_streamer = TextStreamer(tokenizer) + # _ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 800) + # Generate the response + output = model.generate(**inputs, max_new_tokens=1024) + + # Decode the generated response + generated_text = tokenizer.decode(output[0], skip_special_tokens=True) + + # Extract the response part if needed (assuming the response starts after "### Response:") + response_start = generated_text.find("### Response:") + len("### Response:") + response = generated_text[response_start:].strip() + + # Format the response in Markdown + # markdown_response = f"{response}" + + # Render the markdown response + # display(Markdown(markdown_response)) + return response +``` + +```py +generate_medical_answer( + instruction = "What are the pharmacodynamics of Omeprazole?", + input="Writte the text in plain markdown." +) +``` + + +## Evaluation + +The model have been evaluated with `gpt-4o-mini` with `DeepEval`. +The prompt used is quite strict. This reassures us as to the robustness of the model and its ability to adapt to the new fine-tuned datas. + +- Success Log : [test_case_0](https://app.confident-ai.com/project/clzbc1ind05qj8cmtfa3pjho7/unit-tests/clzbmmq330d5s8cmtdtpm888m/test-cases?pageNumber=1&pageSize=50&status=all&conversational=false&testCaseId=288507) +- Failed Log : [test_case_7](https://app.confident-ai.com/project/clzbc1ind05qj8cmtfa3pjho7/unit-tests/clzbmmq330d5s8cmtdtpm888m/test-cases?pageNumber=1&pageSize=50&status=all&conversational=false&testCaseId=288532) + +| | Answer Relevancy | Correctness (GEval) | Bias | Toxicity | Test Result | % of Passing Tests | +|:---------|-------------------:|----------------------:|-------:|-----------:|:--------------|---------------------:| +| Dataset 1 | 0.89 | 0.8 | 0 | 0 | 22 / 28 tests | 78.57 | +| Dataset 2 | 0.85 | 0.83 | 0 | 0 | 8 / 20 tests | 40 | +| lavita/MedQuAD | 0.95 | 0.81 | 0 | 0 | 14 / 20 tests | 70 | + + +### Evaluation Code + +```py + +def evaluate_llama_alpacare_gpt4(medQA): + # Define the metrics + answer_relevancy_metric = AnswerRelevancyMetric( + threshold=0.7, + model="gpt-4o-mini", + include_reason=True + ) + + bias = BiasMetric( + model="gpt-4o-mini", + include_reason=True, + threshold=0.8 + ) + + toxicity = ToxicityMetric( + model="gpt-4o-mini", + include_reason=True + ) + + correctness_metric = GEval( + name="Correctness", + threshold=0.7, + model="gpt-4o-mini", + criteria="Determine whether the actual output is factually correct based on the expected output, focusing on medical accuracy and adherence to established guidelines.", + evaluation_steps=[ + "Check whether the facts in 'actual output' contradict any facts in 'expected output' or established medical guidelines.", + "Penalizes the omission of medical details, depending on their criticality and especially those that could have an impact on the care provided to the patient or on his or her understanding.", + "Ensure that medical terminology and language used are precise and appropriate for medical context.", + "Assess whether the response adequately addresses the specific medical question posed.", + "Vague language or contradicting opinions are acceptable in general contexts, but factual inaccuracies, especially regarding medical data or guidelines, are not." + ], + evaluation_params=[LLMTestCaseParams.INPUT, LLMTestCaseParams.ACTUAL_OUTPUT] + ) + + test_cases = [] + + # metric = FaithfulnessMetric( + # model="gpt-4o-mini", + # include_reason=True + # ) + + # Loop through the dataset and evaluate + for example in medQA: + question = example['Question'] + expected_output = example['Answer'] + question_focus = example['instruction'] + + + # Generate the actual output + actual_output = generate_medical_answer( + instruction=question, + input=question_focus, + ) + + # Define the test case + test_case = LLMTestCase( + input=question, + actual_output=actual_output, + expected_output=expected_output, + ) + + test_cases.append(test_case) + + evaluate(test_cases, [answer_relevancy_metric, correctness_metric, bias, toxicity]) + +``` + + + +This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library. + +[](https://github.com/unslothai/unsloth) \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..a4ba21b --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "model_type": "llama" +} \ No newline at end of file diff --git a/unsloth.F16.gguf b/unsloth.F16.gguf new file mode 100644 index 0000000..6919123 --- /dev/null +++ b/unsloth.F16.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0ccd286443c3fbcb73f606907aa03fdc17441bfca7e69e659915419bb6a4850 +size 16068891424 diff --git a/unsloth.Q4_K_M.gguf b/unsloth.Q4_K_M.gguf new file mode 100644 index 0000000..9cdf597 --- /dev/null +++ b/unsloth.Q4_K_M.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60bd28a24f9a7d0501647201154b93bb8b8e214f13307d4fecee49769a68a0da +size 4920734496 diff --git a/unsloth.Q5_K_M.gguf b/unsloth.Q5_K_M.gguf new file mode 100644 index 0000000..94a05a6 --- /dev/null +++ b/unsloth.Q5_K_M.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:558e575c23f51459ba447b7053318f079b5d1563f953f2872b33da0fc31a4bd4 +size 5732987680 diff --git a/unsloth.Q8_0.gguf b/unsloth.Q8_0.gguf new file mode 100644 index 0000000..ab1cf35 --- /dev/null +++ b/unsloth.Q8_0.gguf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c65bfd7c741ceb898540892a4acccac32d46218a948a6090920da0aa7960c9df +size 8540771104