Views
No views yet

pip install transformers peft torch1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5# Configuration
6BASE_MODEL_ID = "Qwen/Qwen2.5-7B-Instruct"
7ADAPTER_ID = "YOUR_USERNAME/qwen2.5-social-content-generator"
8
9# Load Base Model
10base_model = AutoModelForCausalLM.from_pretrained(
11 BASE_MODEL_ID,
12 torch_dtype=torch.bfloat16,
13 device_map="auto"
14)
15
16# Load LoRA Adapter
17model = PeftModel.from_pretrained(base_model, ADAPTER_ID)
18tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID)
19
20def generate_content(prompt, max_tokens=150):
21 # Format prompt with ChatML template
22 formatted_prompt = f"<|im_start|>system\nYou are a professional social media content generator.<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n"
23
24 inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
25
26 with torch.no_grad():
27 outputs = model.generate(
28 **inputs,
29 max_new_tokens=max_tokens,
30 temperature=0.7,
31 top_p=0.9,
32 do_sample=True
33 )
34
35 response = tokenizer.decode(outputs[0], skip_special_tokens=True)
36 return response.split("assistant")[-1].strip()
37
38# Example Usage
39print(generate_content("Write a professional LinkedIn post about AI trends in 2026"))| Content Type | Count | Percentage | Description |
|---|---|---|---|
| Short-form | 1,468 | 27% | 8-30 words (Reels, Shorts) |
| Medium-form | 1,831 | 34% | 31-100 words (Captions, Updates) |
| Long-form | 1,987 | 37% | 100+ words (Articles, Threads) |
| Parameter | Value |
|---|---|
| Base Model | Qwen2.5-7B-Instruct |
| Quantization | 4-bit (NF4) |
| LoRA Rank (r) | 16 |
| LoRA Alpha | 32 |
| Target Modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Batch Size | 16 (Effective) |
| Learning Rate | 2e-4 |
| Epochs | 3 |
| Optimizer | paged_adamw_32bit |
Output: Stop scrolling. 🛑 This productivity hack changed everything for me. Focus on one thing at a time. Save this. 📌
Output: AI is not just a buzzword; it's a paradigm shift. In 2026, we are seeing a move towards agentic workflows that autonomously solve complex problems. Organizations that adapt now will lead the market. #AI #Innovation #FutureOfWork
1# Load on CPU
2model = AutoModelForCausalLM.from_pretrained(
3 BASE_MODEL_ID,
4 torch_dtype=torch.float32,
5 device_map="cpu",
6 low_cpu_mem_usage=True
7)
8model = PeftModel.from_pretrained(model, ADAPTER_ID)1@misc{qwen2.5-social-content-generator,
2 author = {Your Name},
3 title = {Social Media Content Generator - Qwen2.5 7B LoRA},
4 year = {2026},
5 publisher = {HuggingFace},
6 howpublished = {\url{https://huggingface.co/YOUR_USERNAME/qwen2.5-social-content-generator}},
7}