Skip to content

Commit 11518ea

Browse files
Merge pull request #135 from MervinPraison/develop
praisonai train final release
2 parents b14eb76 + 1bead59 commit 11518ea

File tree

9 files changed

+63
-21
lines changed

9 files changed

+63
-21
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.11-slim
22
WORKDIR /app
33
COPY . .
4-
RUN pip install flask praisonai==0.0.59rc11 gunicorn markdown
4+
RUN pip install flask praisonai==0.0.59 gunicorn markdown
55
EXPOSE 8080
66
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]

docs/api/praisonai/deploy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h2 id="raises">Raises</h2>
110110
file.write(&#34;FROM python:3.11-slim\n&#34;)
111111
file.write(&#34;WORKDIR /app\n&#34;)
112112
file.write(&#34;COPY . .\n&#34;)
113-
file.write(&#34;RUN pip install flask praisonai==0.0.59rc11 gunicorn markdown\n&#34;)
113+
file.write(&#34;RUN pip install flask praisonai==0.0.59 gunicorn markdown\n&#34;)
114114
file.write(&#34;EXPOSE 8080\n&#34;)
115115
file.write(&#39;CMD [&#34;gunicorn&#34;, &#34;-b&#34;, &#34;0.0.0.0:8080&#34;, &#34;api:app&#34;]\n&#39;)
116116

praisonai.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Praisonai < Formula
33

44
desc "AI tools for various AI applications"
55
homepage "https://github.com/MervinPraison/PraisonAI"
6-
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/0.0.59rc11.tar.gz"
6+
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/0.0.59.tar.gz"
77
sha256 "1828fb9227d10f991522c3f24f061943a254b667196b40b1a3e4a54a8d30ce32" # Replace with actual SHA256 checksum
88
license "MIT"
99

praisonai/cli.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,24 @@ def main(self):
133133
package_root = os.path.dirname(os.path.abspath(__file__))
134134
config_yaml_destination = os.path.join(os.getcwd(), 'config.yaml')
135135

136-
# Generate config.yaml using the function
137-
config = generate_config(
138-
model_name=args.model,
139-
hf_model_name=args.hf,
140-
ollama_model_name=args.ollama,
141-
dataset=[{
142-
"name": args.dataset
143-
}]
144-
)
145-
with open('config.yaml', 'w') as f:
146-
yaml.dump(config, f, default_flow_style=False, indent=2)
147-
136+
# Create config.yaml only if it doesn't exist or --model or --dataset is provided
137+
if not os.path.exists(config_yaml_destination) or args.model or args.dataset:
138+
config = generate_config(
139+
model_name=args.model,
140+
hf_model_name=args.hf,
141+
ollama_model_name=args.ollama,
142+
dataset=[{
143+
"name": args.dataset
144+
}]
145+
)
146+
with open('config.yaml', 'w') as f:
147+
yaml.dump(config, f, default_flow_style=False, indent=2)
148+
149+
# Overwrite huggingface_save and ollama_save if --hf or --ollama are provided
150+
if args.hf:
151+
config["huggingface_save"] = "true"
152+
if args.ollama:
153+
config["ollama_save"] = "true"
148154

149155
if 'init' in sys.argv:
150156
from praisonai.setup.setup_conda_env import main as setup_conda_main

praisonai/deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def create_dockerfile(self):
5656
file.write("FROM python:3.11-slim\n")
5757
file.write("WORKDIR /app\n")
5858
file.write("COPY . .\n")
59-
file.write("RUN pip install flask praisonai==0.0.59rc11 gunicorn markdown\n")
59+
file.write("RUN pip install flask praisonai==0.0.59 gunicorn markdown\n")
6060
file.write("EXPOSE 8080\n")
6161
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
6262

praisonai/inc/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def generate_config(
3838
"""Generates the configuration for PraisonAI with dynamic overrides."""
3939

4040
config = {
41-
"ollama_save": ollama_save or "false",
42-
"huggingface_save": huggingface_save or "false",
43-
"train": train or "false",
41+
"ollama_save": ollama_save or "true",
42+
"huggingface_save": huggingface_save or "true",
43+
"train": train or "true",
4444

4545
"model_name": model_name or "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit",
4646
"hf_model_name": hf_model_name or "mervinpraison/llama-3.1-tamilan-8B-test",

praisonai/setup/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ model_parameters: "8b"
1010
max_seq_length: 2048
1111
load_in_4bit: true
1212
lora_r: 16
13-
lora_target_modules:
13+
lora_target_modules:
1414
- "q_proj"
1515
- "k_proj"
1616
- "v_proj"

praisonai/train.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def train_model(self):
142142
),
143143
)
144144
trainer.train()
145+
self.model.save_pretrained("lora_model") # Local saving
146+
self.tokenizer.save_pretrained("lora_model")
145147

146148
def inference(self, instruction, input_text):
147149
FastLanguageModel.for_inference(self.model)
@@ -158,6 +160,17 @@ def inference(self, instruction, input_text):
158160
inputs = self.tokenizer([alpaca_prompt.format(instruction, input_text, "")], return_tensors="pt").to("cuda")
159161
outputs = self.model.generate(**inputs, max_new_tokens=64, use_cache=True)
160162
print(self.tokenizer.batch_decode(outputs))
163+
164+
def load_model(self):
165+
"""Loads the model and tokenizer using the FastLanguageModel library."""
166+
from unsloth import FastLanguageModel
167+
model, tokenizer = FastLanguageModel.from_pretrained(
168+
model_name=self.config["output_dir"],
169+
max_seq_length=2048,
170+
dtype=None,
171+
load_in_4bit=self.config["load_in_4bit"],
172+
)
173+
return model, tokenizer
161174

162175
def save_model_merged(self):
163176
if os.path.exists(self.config["hf_model_name"]):
@@ -176,9 +189,22 @@ def push_model_gguf(self):
176189
quantization_method=self.config["quantization_method"],
177190
token=os.getenv('HF_TOKEN')
178191
)
192+
193+
def save_model_gguf(self):
194+
self.model.save_pretrained_gguf(
195+
self.config["hf_model_name"],
196+
self.tokenizer,
197+
quantization_method="q4_k_m"
198+
)
179199

180200
def prepare_modelfile_content(self):
181201
output_model = self.config["hf_model_name"]
202+
gguf_path = f"{output_model}/unsloth.Q4_K_M.gguf"
203+
204+
# Check if the GGUF file exists. If not, generate it ## TODO Multiple Quantisation other than Q4_K_M.gguf
205+
if not os.path.exists(gguf_path):
206+
self.model, self.tokenizer = self.load_model()
207+
self.save_model_gguf()
182208
return f"""FROM {output_model}/unsloth.Q4_K_M.gguf
183209
184210
TEMPLATE \"\"\"Below are some instructions that describe some tasks. Write responses that appropriately complete each request.{{{{ if .Prompt }}}}
@@ -215,10 +241,20 @@ def run(self):
215241
self.train_model()
216242

217243
if self.config.get("huggingface_save", "true").lower() == "true":
244+
self.model, self.tokenizer = self.load_model()
218245
self.save_model_merged()
219246

220247
if self.config.get("huggingface_save_gguf", "true").lower() == "true":
248+
self.model, self.tokenizer = self.load_model()
221249
self.push_model_gguf()
250+
251+
# if self.config.get("save_gguf", "true").lower() == "true": ## TODO
252+
# self.model, self.tokenizer = self.load_model()
253+
# self.save_model_gguf()
254+
255+
# if self.config.get("save_merged", "true").lower() == "true": ## TODO
256+
# self.model, self.tokenizer = self.load_model()
257+
# self.save_model_merged()
222258

223259
if self.config.get("ollama_save", "true").lower() == "true":
224260
self.create_and_push_ollama_model()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "PraisonAI"
3-
version = "0.0.59rc11"
3+
version = "0.0.59"
44
description = "PraisonAI application combines AutoGen and CrewAI or similar frameworks into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customization, and efficient human-agent collaboration."
55
authors = ["Mervin Praison"]
66
license = ""

0 commit comments

Comments
 (0)