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

Original implementation #35

Open
wants to merge 5 commits into
base: original-implementation
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/tree-of-thoughts.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
T = 3
b = 5
vth = 0.5
pruning_threshold = 0.5
timeout = 10
confidence = 0.8 #cmodel is confident on performance
max_iterations = 40 #tree branh nodes
convergence_threshold = 0.01
convergence_count = 5

#call the solve emthod with the input problem and other params
solution = tree_of_thoughts.solve(input_problem, k, T, b, vth, timeout, confidence, max_iterations, convergence_threshold, convergence_count)
solution = tree_of_thoughts.solve(input_problem, k, T, b, vth, timeout, pruning_threshold, confidence, max_iterations, convergence_threshold, convergence_count)



Expand Down
14 changes: 9 additions & 5 deletions huggingfaceExample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tree_of_thoughts.treeofthoughts import OpenAILanguageModel, GuidanceOpenAILanguageModel, TreeofThoughts, OptimizedOpenAILanguageModel, OptimizedTreeofThoughts, HuggingLanguageModel
from tree_of_thoughts.treeofthoughts import TreeofThoughts, OptimizedTreeofThoughts
from tree_of_thoughts.huggingModels import HuggingLanguageModel
# from transformers import AutoModelForCausalLM, AutoTokenizer

# model_name="gpt2"
Expand All @@ -18,9 +19,10 @@
# return generated_text

# Initialize the HuggingLanguageModel with the GPT-2 model
model_name = "gpt2"
model_name = r"C:\Users\David\.cache\huggingface\modules\transformers_modules\chatglm6b"
tokenizer_name = r"C:\Users\David\.cache\huggingface\modules\transformers_modules\chatglm6b"
model = HuggingLanguageModel(model_name,
model_Tokenizer="gpt2",
model_tokenizer=tokenizer_name,
verbose=True)


Expand All @@ -35,7 +37,6 @@
# value or vote
evaluation_strategy = "value"


gpt2_model = HuggingLanguageModel(model_name)

tree_of_thoughts= OptimizedTreeofThoughts(model, search_algorithm)
Expand All @@ -50,9 +51,12 @@
max_iterations = 40 #tree branh nodes
convergence_threshold = 0.01
convergence_count = 5
pruning_threshold = 0.3

#call the solve emthod with the input problem and other params
solution = tree_of_thoughts.solve(input_problem, k, T, b, vth, timeout, confidence, max_iterations, convergence_threshold, convergence_count)
solution = tree_of_thoughts.solve(input_problem, k, T, b, vth, timeout,
confidence_threshold=confidence, max_iterations=max_iterations,
convergence_threshold=convergence_threshold, convergence_count=convergence_count)

#use the solution in your production environment
print(f"solution: {solution}")
Binary file modified tree_of_thoughts/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file modified tree_of_thoughts/__pycache__/guidanceModels.cpython-311.pyc
Binary file not shown.
Binary file modified tree_of_thoughts/__pycache__/huggingModels.cpython-311.pyc
Binary file not shown.
Binary file modified tree_of_thoughts/__pycache__/openaiModels.cpython-311.pyc
Binary file not shown.
Binary file modified tree_of_thoughts/__pycache__/treeofthoughts.cpython-311.pyc
Binary file not shown.
Binary file modified tree_of_thoughts/__pycache__/treeofthoughts.cpython-39.pyc
Binary file not shown.
8 changes: 4 additions & 4 deletions tree_of_thoughts/huggingModels.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModel
from transformers import pipeline
from .abstractLanguageModel import AbstractLanguageModel


class HuggingLanguageModel(AbstractLanguageModel):
def __init__(self, model_name, model_tokenizer=None, verbose=False):
self.model = AutoModelForCausalLM.from_pretrained(model_name)
self.tokenizer = AutoTokenizer.from_pretrained(model_tokenizer or model_name)
self.model = AutoModel.from_pretrained(model_name, trust_remote_code=True).to('cpu', dtype=float)
self.tokenizer = AutoTokenizer.from_pretrained(model_tokenizer or model_name, trust_remote_code=True)
self.verbose = verbose

def generate_thoughts(self, state, k, max_length=100):
Expand All @@ -28,7 +28,7 @@ def generate_thoughts(self, state, k, max_length=100):

return thoughts

def evaluate_states(self, states, inital_prompt, max_length=10):
def evaluate_states(self, states, initial_prompt, max_length=10):
state_values = {}
for state in states:
state_text = ' '.join(state)
Expand Down
Empty file removed tree_of_thoughts/log.txt
Empty file.
Loading