Views
No views yet
unsloth/Qwen3-14B base model (which itself is based on Qwen/Qwen2-14B). This model has been specifically tailored to enhance logical and deductive reasoning capabilities in the Arabic language, while also maintaining its general conversational abilities. The fine-tuning process utilized LoRA (Low-Rank Adaptation) with the Unsloth library for high training efficiency. The LoRA weights were then merged with the base model to produce this standalone 16-bit (float16) precision model.unsloth/Qwen3-14B: Leverages the power and performance of the Qwen3 14-billion parameter base model.<think>...</think> tags) before providing the final answer, which is beneficial for tasks requiring explanation or complex inference.beetlware/arabic-reasoning-dataset-logic, available on the Hugging Face Hub. This dataset includes tasks variés types of reasoning (deduction, induction, abduction), with each task comprising the question text, a proposed answer, and a detailed solution including thinking steps.<think>...</think> tags) followed by the final answer.unsloth/Qwen3-14Br (rank): 32lora_alpha: 32target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]lora_dropout: 0bias: "none"SFTTrainer)max_seq_length): 2048 tokensper_device_train_batch_size: 2gradient_accumulation_steps: 4 (simulating a total batch size of 8)warmup_steps: 5max_steps: 30 (in the notebook, adjustable for a full run)learning_rate: 2e-4 (recommended to reduce to 2e-5 for longer training runs)optim: "adamw_8bit"merged_16bit (float16) precision.transformers library:1from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
2import torch
3
4model_id = "beetlware/Bee1reason-arabic-Qwen-14B"
5
6# Load the Tokenizer
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8
9# Load the Model
10model = AutoModelForCausalLM.from_pretrained(
11 model_id,
12 torch_dtype=torch.bfloat16, # or torch.float16 if bfloat16 is not supported
13 device_map="auto", # Distributes the model on available devices (GPU/CPU)
14)
15
16# Ensure the model is in evaluation mode for inference
17model.eval()1user_prompt_with_thinking_request = "استخدم التفكير المنطقي خطوة بخطوة: إذا كان لدي 4 تفاحات والشجرة فيها 20 تفاحة، فكم تفاحة لدي إجمالاً؟" # "Use step-by-step logical thinking: If I have 4 apples and the tree has 20 apples, how many apples do I have in total?"
2
3messages_with_thinking = [
4 {"role": "user", "content": user_prompt_with_thinking_request}
5]
6
7# Apply the chat template
8# Qwen3 uses a specific chat template. tokenizer.apply_chat_template is the correct way to format it.
9chat_prompt_with_thinking = tokenizer.apply_chat_template(
10 messages_with_thinking,
11 tokenize=False,
12 add_generation_prompt=True # Important for adding the assistant's generation prompt
13)
14
15inputs_with_thinking = tokenizer(chat_prompt_with_thinking, return_tensors="pt").to(model.device)
16
17print("\n--- Inference with Thinking Request (Example) ---")
18streamer_think = TextStreamer(tokenizer, skip_prompt=True)
19with torch.no_grad(): # Important to disable gradients during inference
20 outputs_think = model.generate(
21 **inputs_with_thinking,
22 max_new_tokens=512,
23 temperature=0.6, # Recommended settings for reasoning by Qwen team
24 top_p=0.95,
25 top_k=20,
26 pad_token_id=tokenizer.eos_token_id,
27 streamer=streamer_think
28 )1# --- Example for Normal Inference (Conversation without explicit thinking request) ---
2user_prompt_normal = "ما هي عاصمة مصر؟" # "What is the capital of Egypt?"
3messages_normal = [
4 {"role": "user", "content": user_prompt_normal}
5]
6
7chat_prompt_normal = tokenizer.apply_chat_template(
8 messages_normal,
9 tokenize=False,
10 add_generation_prompt=True
11)
12inputs_normal = tokenizer(chat_prompt_normal, return_tensors="pt").to(model.device)
13
14print("\n\n--- Normal Inference (Example) ---")
15streamer_normal = TextStreamer(tokenizer, skip_prompt=True)
16with torch.no_grad():
17 outputs_normal = model.generate(
18 **inputs_normal,
19 max_new_tokens=100,
20 temperature=0.7, # Recommended settings for normal chat
21 top_p=0.8,
22 top_k=20,
23 pad_token_id=tokenizer.eos_token_id,
24 streamer=streamer_normal
25 )1
2pip install vllm1python -m vllm.entrypoints.openai.api_server \
2 --model beetlware/Bee1reason-arabic-Qwen-14B \
3 --tokenizer beetlware/Bee1reason-arabic-Qwen-14B \
4 --dtype bfloat16 \
5 --max-model-len 2048 \
6 # --tensor-parallel-size N # If you have multiple GPUs
7 # --gpu-memory-utilization 0.9 # To adjust GPU memory usage
81
2import openai
3
4client = openai.OpenAI(
5 base_url="http://localhost:8000/v1", # VLLM server address
6 api_key="dummy_key" # VLLM doesn't require an actual API key by default
7)
8
9completion = client.chat.completions.create(
10 model="beetlware/Bee1reason-arabic-Qwen-14B", # Model name as specified in VLLM
11 messages=[
12 {"role": "user", "content": "اشرح نظرية النسبية العامة بكلمات بسيطة."} # "Explain the theory of general relativity in simple terms."
13 ],
14 max_tokens=256,
15 temperature=0.7,
16 stream=True # To enable streaming
17)
18
19print("Streaming response from VLLM:")
20full_response = ""
21for chunk in completion:
22 if chunk.choices[0].delta.content is not None:
23 token = chunk.choices[0].delta.content
24 print(token, end="", flush=True)
25 full_response += token
26print("\n--- End of stream ---")
27