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

Work evolutionary model merge package on load #40

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions package/samplers/evo_merge/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
from langchain.llms.base import BaseLLM
from langchain.prompts import PromptTemplate
import optuna
import optunahub

from package.samplers.evo_merge.sampler import EvoMergeSampler
from package.samplers.evo_merge.trial import EvoMergeTrial


# EvoMergeSampler = optunahub.load_module("samplers/evo_merge").EvoMergeSampler
# EvoMergeTrial = optunahub.load_module("samplers/evo_merge").EvoMergeTrial
module = optunahub.load_module("samplers/evo_merge")
EvoMergeSampler = module.EvoMergeSampler
EvoMergeTrial = module.EvoMergeTrial

TEMPLATE = "質問に答えなさい。質問: {question} 回答: "

Expand All @@ -39,7 +38,7 @@ def eval_jaqket(llm_chain: LLMChain) -> int:
out = llm_chain.run(question=problem["question"])
if len(out.strip()) != 0:
out = out.strip().split()[0].strip()
if problem["answer_number"] in out:
if str(problem["answer_number"]) in out:
correct += 1

return correct
Expand Down
2 changes: 1 addition & 1 deletion package/samplers/evo_merge/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def sample_model(self, study: Study, trial: EvoMergeTrial) -> BaseLLM:
def load_model(model_id: str) -> BaseLLM:
bnbconf = BitsAndBytesConfig(load_in_4bit=True)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.frm_pretrained(model_id, quantization_config=bnbconf)
model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnbconf)
llm = HuggingFacePipeline(
pipeline=pipeline(
"text-generation",
Expand Down