初始化项目,由ModelHub XC社区提供模型

Model: ankitkushwaha90/Qwen3-1.7BSFTLoRA
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-09-24 19:21:19 +08:00
commit 8da43e2755
16 changed files with 152882 additions and 0 deletions

36
.gitattributes vendored Normal file
View File

@@ -0,0 +1,36 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
tokenizer.json filter=lfs diff=lfs merge=lfs -text

View File

@@ -0,0 +1,237 @@
#!/usr/bin/env python3
import os
import torch
from datasets import load_dataset
from transformers import (
AutoTokenizer,
AutoModelForCausalLM,
)
from peft import (
LoraConfig,
get_peft_model,
)
from trl import (
SFTTrainer,
SFTConfig,
)
# ============================================================
# CONFIG
# ============================================================
MODEL_NAME = "./Qwen3-1.7B"
DATASET_PATH = "./dataset/train.jsonl"
OUTPUT_DIR = "./qwen3_lora_sft_pro_try"
MERGED_DIR = OUTPUT_DIR + "_merged"
MAX_LENGTH = 512
os.makedirs(OUTPUT_DIR, exist_ok=True)
# ============================================================
# TOKENIZER
# ============================================================
print("Loading tokenizer...")
tokenizer = AutoTokenizer.from_pretrained(
MODEL_NAME,
trust_remote_code=True,
)
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"
# ============================================================
# MODEL
# ============================================================
print("Loading model...")
dtype = (
torch.bfloat16
if torch.cuda.is_available()
and torch.cuda.is_bf16_supported()
else torch.float16
)
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
trust_remote_code=True,
torch_dtype=dtype,
device_map="auto",
)
model.config.use_cache = False
model.gradient_checkpointing_enable()
# ============================================================
# LORA CONFIG
# ============================================================
print("Applying LoRA...")
lora_config = LoraConfig(
r=16,
lora_alpha=32,
lora_dropout=0.05,
bias="none",
task_type="CAUSAL_LM",
target_modules=[
"q_proj",
"k_proj",
"v_proj",
"o_proj",
"gate_proj",
"up_proj",
"down_proj",
],
)
model = get_peft_model(
model,
lora_config,
)
model.print_trainable_parameters()
# ============================================================
# DATASET
# ============================================================
print("Loading dataset...")
dataset = load_dataset(
"json",
data_files=DATASET_PATH,
split="train",
)
def preprocess(example):
text = tokenizer.apply_chat_template(
example["messages"],
tokenize=False,
add_generation_prompt=False,
)
return {
"text": text
}
dataset = dataset.map(
preprocess,
remove_columns=dataset.column_names,
)
print(dataset)
# ============================================================
# TRAINING CONFIG
# ============================================================
training_args = SFTConfig(
output_dir=OUTPUT_DIR,
max_length=MAX_LENGTH,
packing=True,
per_device_train_batch_size=1,
gradient_accumulation_steps=8,
num_train_epochs=3,
learning_rate=2e-4,
warmup_ratio=0.03,
lr_scheduler_type="cosine",
weight_decay=0.05,
logging_steps=10,
save_steps=500,
save_total_limit=3,
bf16=torch.cuda.is_available()
and torch.cuda.is_bf16_supported(),
fp16=not (
torch.cuda.is_available()
and torch.cuda.is_bf16_supported()
),
report_to="none",
dataset_text_field="text",
)
# ============================================================
# TRAINER
# ============================================================
print("Initializing trainer...")
trainer = SFTTrainer(
model=model,
args=training_args,
train_dataset=dataset,
processing_class=tokenizer,
)
# ============================================================
# TRAIN
# ============================================================
print("Starting training...")
trainer.train()
print("Training completed.")
# ============================================================
# SAVE LORA ADAPTER
# ============================================================
print("Saving LoRA adapter...")
trainer.save_model(OUTPUT_DIR)
tokenizer.save_pretrained(OUTPUT_DIR)
# ============================================================
# MERGE LORA
# ============================================================
print("Merging LoRA into base model...")
merged_model = model.merge_and_unload()
merged_model.save_pretrained(
MERGED_DIR,
safe_serialization=True,
)
tokenizer.save_pretrained(
MERGED_DIR,
)
print(f"Merged model saved to: {MERGED_DIR}")
print("Done.")

213
README.md Normal file
View File

@@ -0,0 +1,213 @@
---
language:
- en
license: apache-2.0
base_model: Qwen/Qwen3-1.7B
library_name: transformers
pipeline_tag: text-generation
tags:
- qwen3
- causal-lm
- instruction-tuned
- sft
- lora
- peft
- trl
- transformers
- pytorch
- fine-tuning
datasets:
- custom
---
# Qwen3-1.7B SFT LoRA
A supervised fine-tuned (SFT) version of **Qwen3-1.7B** trained using **LoRA (Low-Rank Adaptation)** with the **TRL SFTTrainer**. This model is designed for instruction-following tasks while keeping the number of trainable parameters low through parameter-efficient fine-tuning (PEFT).
## Model Details
| Property | Value |
|----------|--------|
| Base Model | Qwen/Qwen3-1.7B |
| Architecture | Qwen3ForCausalLM |
| Fine-tuning Method | Supervised Fine-Tuning (SFT) |
| PEFT Method | LoRA |
| Framework | Transformers + TRL + PEFT |
| Precision | bfloat16 |
| Library | Hugging Face Transformers |
| Training | SFTTrainer |
---
# Model Architecture
The model is based on **Qwen3-1.7B** with the following architecture:
- Architecture: `Qwen3ForCausalLM`
- Hidden Size: **2048**
- Intermediate Size: **6144**
- Layers: **28**
- Attention Heads: **16**
- Key/Value Heads: **8**
- Head Dimension: **128**
- Activation Function: **SiLU**
- Context Length: **40,960 tokens**
- Vocabulary Size: **151,936**
- Precision: **bfloat16**
- RMSNorm Epsilon: **1e-6**
- RoPE Theta: **1,000,000**
- Attention Dropout: **0.0**
---
# Fine-tuning Method
The model was fine-tuned using **Parameter-Efficient Fine-Tuning (PEFT)** with **LoRA**.
Training stack:
- 🤗 Transformers
- 🤗 Datasets
- 🤗 PEFT
- 🤗 TRL
- PyTorch
### Libraries
```python
from datasets import load_dataset
from transformers import (
AutoTokenizer,
AutoModelForCausalLM,
)
from peft import (
LoraConfig,
get_peft_model,
)
from trl import (
SFTTrainer,
SFTConfig,
)
```
---
# Training Pipeline
1. Load the dataset using Hugging Face Datasets.
2. Load the Qwen3-1.7B tokenizer.
3. Load the Qwen3-1.7B base model.
4. Configure LoRA adapters.
5. Apply PEFT to the base model.
6. Configure SFTTrainer.
7. Fine-tune using supervised instruction data.
8. Save LoRA adapters or merge them into the base model.
---
# Intended Uses
This model is intended for:
- Instruction Following
- Question Answering
- Chat Applications
- Text Generation
- Code Assistance
- Educational Tasks
- Research
- AI Assistants
---
# Limitations
- May generate incorrect or hallucinated information.
- Responses depend heavily on prompt quality.
- Not intended for medical, legal, or financial advice without human verification.
- Performance depends on the quality and diversity of the fine-tuning dataset.
---
# Example Usage
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "ankitkushwaha90/<your-model-name>"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
messages = [
{
"role": "user",
"content": "Explain what LoRA fine-tuning is."
}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.7,
top_p=0.95,
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```
---
# Training Framework
- Transformers
- TRL
- PEFT
- Datasets
- PyTorch
---
# Citation
If you use this model in your research or applications, please cite:
```bibtex
@software{qwen3_1_7b_sft_lora,
author = {Ankit Kushwaha},
title = {Qwen3-1.7B SFT LoRA},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/ankitkushwaha90}
}
```
---
# Acknowledgements
This model is built upon the excellent **Qwen3-1.7B** base model and fine-tuned using the Hugging Face ecosystem, including:
- Transformers
- TRL
- PEFT
- Datasets
- PyTorch
Special thanks to the Qwen and Hugging Face teams for providing open-source tooling and models.

28
added_tokens.json Normal file
View File

@@ -0,0 +1,28 @@
{
"</think>": 151668,
"</tool_call>": 151658,
"</tool_response>": 151666,
"<think>": 151667,
"<tool_call>": 151657,
"<tool_response>": 151665,
"<|box_end|>": 151649,
"<|box_start|>": 151648,
"<|endoftext|>": 151643,
"<|file_sep|>": 151664,
"<|fim_middle|>": 151660,
"<|fim_pad|>": 151662,
"<|fim_prefix|>": 151659,
"<|fim_suffix|>": 151661,
"<|im_end|>": 151645,
"<|im_start|>": 151644,
"<|image_pad|>": 151655,
"<|object_ref_end|>": 151647,
"<|object_ref_start|>": 151646,
"<|quad_end|>": 151651,
"<|quad_start|>": 151650,
"<|repo_name|>": 151663,
"<|video_pad|>": 151656,
"<|vision_end|>": 151653,
"<|vision_pad|>": 151654,
"<|vision_start|>": 151652
}

89
chat_template.jinja Normal file
View File

@@ -0,0 +1,89 @@
{%- if tools %}
{{- '<|im_start|>system\n' }}
{%- if messages[0].role == 'system' %}
{{- messages[0].content + '\n\n' }}
{%- endif %}
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
{%- for tool in tools %}
{{- "\n" }}
{{- tool | tojson }}
{%- endfor %}
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
{%- else %}
{%- if messages[0].role == 'system' %}
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for message in messages[::-1] %}
{%- set index = (messages|length - 1) - loop.index0 %}
{%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
{%- set ns.multi_step_tool = false %}
{%- set ns.last_query_index = index %}
{%- endif %}
{%- endfor %}
{%- for message in messages %}
{%- if message.content is string %}
{%- set content = message.content %}
{%- else %}
{%- set content = '' %}
{%- endif %}
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
{{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
{%- elif message.role == "assistant" %}
{%- set reasoning_content = '' %}
{%- if message.reasoning_content is string %}
{%- set reasoning_content = message.reasoning_content %}
{%- else %}
{%- if '</think>' in content %}
{%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
{%- set content = content.split('</think>')[-1].lstrip('\n') %}
{%- endif %}
{%- endif %}
{%- if loop.index0 > ns.last_query_index %}
{%- if loop.last or (not loop.last and reasoning_content) %}
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + content }}
{%- endif %}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + content }}
{%- endif %}
{%- if message.tool_calls %}
{%- for tool_call in message.tool_calls %}
{%- if (loop.first and content) or (not loop.first) %}
{{- '\n' }}
{%- endif %}
{%- if tool_call.function %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{{- '<tool_call>\n{"name": "' }}
{{- tool_call.name }}
{{- '", "arguments": ' }}
{%- if tool_call.arguments is string %}
{{- tool_call.arguments }}
{%- else %}
{{- tool_call.arguments | tojson }}
{%- endif %}
{{- '}\n</tool_call>' }}
{%- endfor %}
{%- endif %}
{{- '<|im_end|>\n' }}
{%- elif message.role == "tool" %}
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
{{- '<|im_start|>user' }}
{%- endif %}
{{- '\n<tool_response>\n' }}
{{- content }}
{{- '\n</tool_response>' }}
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
{{- '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
{{- '<|im_start|>assistant\n' }}
{%- if enable_thinking is defined and enable_thinking is false %}
{{- '<think>\n\n</think>\n\n' }}
{%- endif %}
{%- endif %}

60
config.json Normal file
View File

@@ -0,0 +1,60 @@
{
"architectures": [
"Qwen3ForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"dtype": "bfloat16",
"eos_token_id": 151645,
"head_dim": 128,
"hidden_act": "silu",
"hidden_size": 2048,
"initializer_range": 0.02,
"intermediate_size": 6144,
"layer_types": [
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention"
],
"max_position_embeddings": 40960,
"max_window_layers": 28,
"model_type": "qwen3",
"num_attention_heads": 16,
"num_hidden_layers": 28,
"num_key_value_heads": 8,
"pad_token_id": 151643,
"rms_norm_eps": 1e-06,
"rope_scaling": null,
"rope_theta": 1000000,
"sliding_window": null,
"tie_word_embeddings": true,
"transformers_version": "4.57.3",
"use_cache": false,
"use_sliding_window": false,
"vocab_size": 151936
}

232
dataset/generate_dataset.py Normal file
View File

@@ -0,0 +1,232 @@
import json
from itertools import product
SYSTEM_PROMPT = (
"You are a helpful, accurate, and concise AI assistant. "
"Answer using the provided knowledge without inventing unsupported facts."
)
KNOWLEDGE = {
"AnkitKushwaha90": {
"aliases": [
"AnkitKushwaha90",
"Ankit Kushwaha",
"Ankit Kushwaha90",
"the AnkitKushwaha90 profile",
"0xAnkit",
],
"summary": (
"Ankit Kushwaha (AnkitKushwaha90) is a Cybersecurity and AI Research Enthusiast "
"with a strong focus on Python, transformer architectures, backend development, "
"and practical software engineering. He is the founder/owner of Tech3Space and "
"maintains active presence across GitHub, Hugging Face, LinkedIn, and his own platform."
),
"facts": [
"Cybersecurity and AI Research Enthusiast.",
"Works at Apple (as per LinkedIn).",
"Graduated from Dr. A.P.J. Abdul Kalam Technical University.",
"Deep interest in transformer architectures, kernel-level systems, and high-performance computing.",
"Active on GitHub under tech3space and Hugging Face as ankitkushwaha90.",
"Focuses on practical projects involving FastAPI, Streamlit, Docker, and machine learning.",
"Explores interdisciplinary topics: Military Aviation, Radar Systems, LIDAR, Sensor Fusion, and Pattern-Based Learning.",
],
"links": [
"LinkedIn: https://www.linkedin.com/in/ankitkushwaha90/",
"Hugging Face: https://huggingface.co/ankitkushwaha90",
"GitHub (Tech3Space): https://github.com/tech3space",
],
},
"Tech3Space": {
"aliases": [
"Tech3Space",
"the Tech3Space initiative",
"Tech3Space | Systems Research Studio",
"tech3space.com",
],
"summary": (
"Tech3Space is a technology platform and research studio founded by Ankit Kushwaha. "
"It serves as a hub for researchers, developers, and tech enthusiasts to share knowledge, "
"upload resources, build communities, and collaborate on cutting-edge topics like "
"Transformers, Cybersecurity, AI, and high-performance systems. The platform emphasizes "
"practical learning, research collaboration, and open knowledge sharing."
),
"facts": [
"A comprehensive platform for sharing research papers, code, notes, and building communities.",
"Features include AI-Powered Research Assistant, post/note sharing, resume/PDF uploads, and real-time chat.",
"Strong focus on Transformers, Cybersecurity, Low-Latency Networking, and Systems Research.",
"GitHub organization (github.com/tech3space) contains repositories on transformer deep-dives, kernel drivers, cybersecurity tools, and assembly.",
"Website: https://tech3space.com/ – described as 'The ultimate platform for researchers, developers, and tech enthusiasts.'",
"Community stats (as advertised): 50,000+ active members, 1,200+ communities.",
],
"links": [
"Official Website: https://tech3space.com/",
"GitHub: https://github.com/tech3space",
"Alternative domains: https://www.tech3space.online, https://www.tech3space.in",
],
},
"HuggingFace_Ankit": {
"aliases": [
"ankitkushwaha90 on Hugging Face",
"Tech3Space on HF",
],
"summary": (
"AnkitKushwaha90's Hugging Face profile (Tech3Space) where he shares models, "
"datasets, and spaces focused on AI/ML, cybersecurity, and technical notes."
),
"facts": [
"Shares models like safetensor-related projects and fine-tuning experiments.",
"Datasets include Sanskrit dataset, vulnerabilities collection, and Linux/CMD command collections.",
"Focus areas: Cybersecurity & AI, Radar Systems, LIDAR, Military Aviation, and Sensor Fusion.",
"Maintains an 'Anonymous Researcher' approach focused purely on knowledge sharing.",
],
"links": [
"Profile: https://huggingface.co/ankitkushwaha90"
],
}
}
QUESTION_TEMPLATES = [
"Who is {}?",
"What is {}?",
"Tell me about {}.",
"Explain {}.",
"Describe {}.",
"Give an overview of {}.",
"Can you introduce {}?",
"What do you know about {}?",
]
DETAIL_REQUESTS = [
"What are the main interests of {}?",
"Summarize {}.",
"Provide a detailed explanation of {}.",
"List the key focus areas of {}.",
]
FOLLOW_UPS = [
(
"Tell me about {}.",
"Can you summarize it in a few sentences?",
),
(
"What is {}?",
"What are its main focus areas?",
),
]
def example(messages):
return {
"messages": [{"role": "system", "content": SYSTEM_PROMPT}] + messages
}
dataset = []
for _, info in KNOWLEDGE.items():
aliases = info["aliases"]
summary = info["summary"]
facts = info["facts"]
bullet_answer = (
summary
+ "\n\nKey points:\n- "
+ "\n- ".join(facts)
)
# Summary-style questions
for alias, template in product(aliases, QUESTION_TEMPLATES):
dataset.append(
example(
[
{
"role": "user",
"content": template.format(alias),
},
{
"role": "assistant",
"content": summary,
},
]
)
)
# Detailed questions
for alias, template in product(aliases, DETAIL_REQUESTS):
dataset.append(
example(
[
{
"role": "user",
"content": template.format(alias),
},
{
"role": "assistant",
"content": bullet_answer,
},
]
)
)
# Multi-turn conversations
for alias, (q1, q2) in product(aliases, FOLLOW_UPS):
dataset.append(
example(
[
{
"role": "user",
"content": q1.format(alias),
},
{
"role": "assistant",
"content": summary,
},
{
"role": "user",
"content": q2,
},
{
"role": "assistant",
"content": bullet_answer,
},
]
)
)
# Fact-specific questions
for alias in aliases:
for fact in facts:
dataset.append(
example(
[
{
"role": "user",
"content": f"What is one important fact about {alias}?",
},
{
"role": "assistant",
"content": fact,
},
]
)
)
# Remove duplicates
seen = set()
unique_dataset = []
for item in dataset:
key = json.dumps(item, sort_keys=True)
if key not in seen:
seen.add(key)
unique_dataset.append(item)
with open("train.jsonl", "w", encoding="utf-8") as f:
for item in unique_dataset:
f.write(json.dumps(item, ensure_ascii=False) + "\n")
print("=" * 60)
print(f"Generated {len(unique_dataset)} training examples.")
print("Saved as train.jsonl")
print("=" * 60)

12
generation_config.json Normal file
View File

@@ -0,0 +1,12 @@
{
"do_sample": true,
"eos_token_id": [
151645,
151643
],
"pad_token_id": 151643,
"temperature": 0.6,
"top_k": 20,
"top_p": 0.95,
"transformers_version": "4.57.3"
}

151388
merges.txt Normal file

File diff suppressed because it is too large Load Diff

3
model.safetensors Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:71d6057780ff108f78bfd5422d35103c589d48448a945d6499c9063e59afa617
size 3441185608

View File

@@ -0,0 +1,103 @@
import re
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
MODEL_PATH = "./" # write correct path of model
print("Loading tokenizer...")
tokenizer = AutoTokenizer.from_pretrained(
MODEL_PATH,
trust_remote_code=True,
)
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
print("Loading model...")
model = AutoModelForCausalLM.from_pretrained(
MODEL_PATH,
trust_remote_code=True,
torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
device_map="auto",
)
model.eval()
messages = [
{
"role": "system",
"content": "You are a helpful AI assistant."
}
]
print("=" * 60)
print("Qwen3-1.7B Chat")
print("Type 'exit' to quit")
print("=" * 60)
while True:
question = input("\nYou: ").strip()
if question.lower() in ["exit", "quit"]:
break
if question == "":
continue
messages.append(
{
"role": "user",
"content": question
}
)
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
inputs = tokenizer(
text,
return_tensors="pt",
)
inputs = {k: v.to(model.device) for k, v in inputs.items()}
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=512,
do_sample=True,
temperature=0.7,
top_p=0.9,
repetition_penalty=1.05,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
)
generated = outputs[0][inputs["input_ids"].shape[1]:]
answer = tokenizer.decode(
generated,
skip_special_tokens=True,
)
answer = re.sub(
r"<think>.*?</think>",
"",
answer,
flags=re.DOTALL,
).strip()
print("\nAssistant:", answer)
messages.append(
{
"role": "assistant",
"content": answer
}
)

213
readme.md Normal file
View File

@@ -0,0 +1,213 @@
---
language:
- en
license: apache-2.0
base_model: Qwen/Qwen3-1.7B
library_name: transformers
pipeline_tag: text-generation
tags:
- qwen3
- causal-lm
- instruction-tuned
- sft
- lora
- peft
- trl
- transformers
- pytorch
- fine-tuning
datasets:
- custom
---
# Qwen3-1.7B SFT LoRA
A supervised fine-tuned (SFT) version of **Qwen3-1.7B** trained using **LoRA (Low-Rank Adaptation)** with the **TRL SFTTrainer**. This model is designed for instruction-following tasks while keeping the number of trainable parameters low through parameter-efficient fine-tuning (PEFT).
## Model Details
| Property | Value |
|----------|--------|
| Base Model | Qwen/Qwen3-1.7B |
| Architecture | Qwen3ForCausalLM |
| Fine-tuning Method | Supervised Fine-Tuning (SFT) |
| PEFT Method | LoRA |
| Framework | Transformers + TRL + PEFT |
| Precision | bfloat16 |
| Library | Hugging Face Transformers |
| Training | SFTTrainer |
---
# Model Architecture
The model is based on **Qwen3-1.7B** with the following architecture:
- Architecture: `Qwen3ForCausalLM`
- Hidden Size: **2048**
- Intermediate Size: **6144**
- Layers: **28**
- Attention Heads: **16**
- Key/Value Heads: **8**
- Head Dimension: **128**
- Activation Function: **SiLU**
- Context Length: **40,960 tokens**
- Vocabulary Size: **151,936**
- Precision: **bfloat16**
- RMSNorm Epsilon: **1e-6**
- RoPE Theta: **1,000,000**
- Attention Dropout: **0.0**
---
# Fine-tuning Method
The model was fine-tuned using **Parameter-Efficient Fine-Tuning (PEFT)** with **LoRA**.
Training stack:
- 🤗 Transformers
- 🤗 Datasets
- 🤗 PEFT
- 🤗 TRL
- PyTorch
### Libraries
```python
from datasets import load_dataset
from transformers import (
AutoTokenizer,
AutoModelForCausalLM,
)
from peft import (
LoraConfig,
get_peft_model,
)
from trl import (
SFTTrainer,
SFTConfig,
)
```
---
# Training Pipeline
1. Load the dataset using Hugging Face Datasets.
2. Load the Qwen3-1.7B tokenizer.
3. Load the Qwen3-1.7B base model.
4. Configure LoRA adapters.
5. Apply PEFT to the base model.
6. Configure SFTTrainer.
7. Fine-tune using supervised instruction data.
8. Save LoRA adapters or merge them into the base model.
---
# Intended Uses
This model is intended for:
- Instruction Following
- Question Answering
- Chat Applications
- Text Generation
- Code Assistance
- Educational Tasks
- Research
- AI Assistants
---
# Limitations
- May generate incorrect or hallucinated information.
- Responses depend heavily on prompt quality.
- Not intended for medical, legal, or financial advice without human verification.
- Performance depends on the quality and diversity of the fine-tuning dataset.
---
# Example Usage
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "ankitkushwaha90/<your-model-name>"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
messages = [
{
"role": "user",
"content": "Explain what LoRA fine-tuning is."
}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.7,
top_p=0.95,
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```
---
# Training Framework
- Transformers
- TRL
- PEFT
- Datasets
- PyTorch
---
# Citation
If you use this model in your research or applications, please cite:
```bibtex
@software{qwen3_1_7b_sft_lora,
author = {Ankit Kushwaha},
title = {Qwen3-1.7B SFT LoRA},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/ankitkushwaha90}
}
```
---
# Acknowledgements
This model is built upon the excellent **Qwen3-1.7B** base model and fine-tuned using the Hugging Face ecosystem, including:
- Transformers
- TRL
- PEFT
- Datasets
- PyTorch
Special thanks to the Qwen and Hugging Face teams for providing open-source tooling and models.

25
special_tokens_map.json Normal file
View File

@@ -0,0 +1,25 @@
{
"additional_special_tokens": [
"<|im_start|>",
"<|im_end|>",
"<|object_ref_start|>",
"<|object_ref_end|>",
"<|box_start|>",
"<|box_end|>",
"<|quad_start|>",
"<|quad_end|>",
"<|vision_start|>",
"<|vision_end|>",
"<|vision_pad|>",
"<|image_pad|>",
"<|video_pad|>"
],
"eos_token": {
"content": "<|im_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"pad_token": "<|endoftext|>"
}

BIN
tokenizer.json (Stored with Git LFS) Normal file

Binary file not shown.

239
tokenizer_config.json Normal file
View File

@@ -0,0 +1,239 @@
{
"add_bos_token": false,
"add_prefix_space": false,
"added_tokens_decoder": {
"151643": {
"content": "<|endoftext|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151644": {
"content": "<|im_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151645": {
"content": "<|im_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151646": {
"content": "<|object_ref_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151647": {
"content": "<|object_ref_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151648": {
"content": "<|box_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151649": {
"content": "<|box_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151650": {
"content": "<|quad_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151651": {
"content": "<|quad_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151652": {
"content": "<|vision_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151653": {
"content": "<|vision_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151654": {
"content": "<|vision_pad|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151655": {
"content": "<|image_pad|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151656": {
"content": "<|video_pad|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151657": {
"content": "<tool_call>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151658": {
"content": "</tool_call>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151659": {
"content": "<|fim_prefix|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151660": {
"content": "<|fim_middle|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151661": {
"content": "<|fim_suffix|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151662": {
"content": "<|fim_pad|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151663": {
"content": "<|repo_name|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151664": {
"content": "<|file_sep|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151665": {
"content": "<tool_response>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151666": {
"content": "</tool_response>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151667": {
"content": "<think>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
},
"151668": {
"content": "</think>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": false
}
},
"additional_special_tokens": [
"<|im_start|>",
"<|im_end|>",
"<|object_ref_start|>",
"<|object_ref_end|>",
"<|box_start|>",
"<|box_end|>",
"<|quad_start|>",
"<|quad_end|>",
"<|vision_start|>",
"<|vision_end|>",
"<|vision_pad|>",
"<|image_pad|>",
"<|video_pad|>"
],
"bos_token": null,
"clean_up_tokenization_spaces": false,
"eos_token": "<|im_end|>",
"errors": "replace",
"extra_special_tokens": {},
"model_max_length": 131072,
"pad_token": "<|endoftext|>",
"split_special_tokens": false,
"tokenizer_class": "Qwen2Tokenizer",
"unk_token": null
}

1
vocab.json Normal file

File diff suppressed because one or more lines are too long