Files
xSaherelmWorkspace/Documents/Docs/Developer/Qwen3.5-9B-Configuration-1.html
2026-10-20 22:20:35 +03:30

581 lines
20 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>مستند فنی راه‌اندازی Qwen3.5-9B با Llamafile و AirLLM</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
:root {
--primary: #1a365d;
--primary-light: #2c5282;
--accent: #c9a961;
--accent-dark: #a8893f;
--bg: #faf9f6;
--card-bg: #ffffff;
--text: #1a202c;
--text-muted: #4a5568;
--border: #e2e8f0;
--success: #38a169;
--danger: #e53e3e;
--warning: #dd6b20;
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Vazirmatn', Tahoma, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.9;
font-size: 15px;
padding: 30px 15px;
}
.document-container {
max-width: 950px;
margin: 0 auto;
background: var(--card-bg);
box-shadow: var(--shadow);
border-radius: 12px;
overflow: hidden;
}
.document-header {
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
color: white;
padding: 50px 40px 40px;
position: relative;
border-bottom: 4px solid var(--accent);
}
.document-header::before {
content: '';
position: absolute;
top: 0; right: 0;
width: 200px; height: 200px;
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
border-radius: 50%;
transform: translate(50%, -50%);
}
.header-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
position: relative;
z-index: 1;
}
.company-badge {
display: flex;
align-items: center;
gap: 12px;
}
.company-logo {
width: 60px; height: 60px;
background: var(--accent);
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: 800;
font-size: 10px;
text-align: center;
line-height: 1.2;
}
.doc-meta {
text-align: left;
font-size: 12px;
opacity: 0.9;
}
.doc-meta div { margin-bottom: 3px; }
.document-title {
text-align: center;
position: relative;
z-index: 1;
padding: 20px 0;
}
.document-title .label {
display: inline-block;
background: rgba(201,169,97,0.2);
color: var(--accent);
padding: 4px 16px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
margin-bottom: 15px;
border: 1px solid rgba(201,169,97,0.4);
}
.document-title h1 {
font-size: 26px;
font-weight: 800;
margin-bottom: 10px;
letter-spacing: -0.5px;
}
.document-title h2 {
font-size: 15px;
font-weight: 400;
opacity: 0.9;
}
.document-body {
padding: 40px;
}
.intro-text {
background: linear-gradient(to left, #f7fafc, #edf2f7);
border-right: 4px solid var(--accent);
padding: 20px 25px;
border-radius: 8px;
margin-bottom: 35px;
font-size: 14px;
color: var(--text-muted);
}
.section {
margin-bottom: 40px;
page-break-inside: avoid;
}
.section-header {
display: flex;
align-items: center;
gap: 15px;
padding-bottom: 12px;
border-bottom: 2px solid var(--border);
margin-bottom: 20px;
}
.section-number {
width: 50px; height: 50px;
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 800;
font-size: 20px;
flex-shrink: 0;
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
}
.section-title { flex: 1; }
.section-title h3 {
font-size: 19px;
font-weight: 700;
color: var(--primary);
margin-bottom: 2px;
}
.section-title .subtitle {
font-size: 12px;
color: var(--text-muted);
}
.section-content {
padding-right: 10px;
}
.section-content p {
margin-bottom: 12px;
text-align: justify;
text-indent: 20px;
}
.section-content p.no-indent { text-indent: 0; }
.highlight-box {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #f6e05e;
border-right: 4px solid var(--accent);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.highlight-box strong {
color: var(--accent-dark);
}
.info-box {
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
border: 1px solid #90cdf4;
border-right: 4px solid var(--primary-light);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.success-box {
background: linear-gradient(to left, #f0fff4, #e6fffa);
border: 1px solid #9ae6b4;
border-right: 4px solid var(--success);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.warning-box {
background: linear-gradient(to left, #fffaf0, #fef5e7);
border: 1px solid #fbd38d;
border-right: 4px solid var(--warning);
padding: 18px 22px;
border-radius: 8px;
margin: 20px 0;
font-size: 14px;
}
.styled-table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.styled-table thead {
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
}
.styled-table th {
padding: 14px 16px;
text-align: right;
font-weight: 600;
font-size: 13px;
}
.styled-table td {
padding: 13px 16px;
border-bottom: 1px solid var(--border);
font-size: 13px;
}
.styled-table tbody tr:last-child td { border-bottom: none; }
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
.styled-table .highlight-row {
background: #fffaf0 !important;
font-weight: 600;
}
pre {
background-color: #1a202c;
color: #e2e8f0;
padding: 20px;
border-radius: 8px;
overflow-x: auto;
direction: ltr;
text-align: left;
margin: 15px 0;
font-family: 'Courier New', Courier, monospace;
font-size: 13px;
line-height: 1.6;
border-right: 4px solid var(--accent);
}
code {
font-family: 'Courier New', Courier, monospace;
background-color: #edf2f7;
color: var(--danger);
padding: 2px 6px;
border-radius: 4px;
font-size: 13px;
direction: ltr;
display: inline-block;
}
pre code {
background-color: transparent;
color: inherit;
padding: 0;
}
.conclusion-box {
background: linear-gradient(135deg, var(--primary), var(--primary-light));
color: white;
padding: 30px;
border-radius: 12px;
margin: 30px 0;
text-align: center;
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
}
.conclusion-box h3 {
font-size: 22px;
font-weight: 800;
margin-bottom: 15px;
color: var(--accent);
}
.conclusion-box p {
font-size: 14px;
line-height: 1.8;
text-indent: 0 !important;
margin-bottom: 15px;
}
.conclusion-box .highlight {
background: rgba(201,169,97,0.2);
padding: 15px 20px;
border-radius: 8px;
margin-top: 20px;
border: 1px solid rgba(201,169,97,0.4);
}
.document-footer {
background: var(--primary);
color: white;
padding: 25px 40px;
text-align: center;
font-size: 12px;
margin-top: 40px;
}
.document-footer .footer-brand {
font-weight: 700;
color: var(--accent);
margin-bottom: 5px;
font-size: 14px;
}
.footer-divider {
width: 60px;
height: 2px;
background: var(--accent);
margin: 10px auto;
}
.page-info {
text-align: center;
padding: 15px;
font-size: 11px;
color: var(--text-muted);
border-top: 1px solid var(--border);
margin-top: 30px;
}
@media print {
body { background: white; padding: 0; }
.document-container { box-shadow: none; border-radius: 0; }
.section { page-break-inside: avoid; }
}
@media (max-width: 768px) {
.document-body { padding: 25px 20px; }
.document-header { padding: 30px 20px; }
.header-top { flex-direction: column; gap: 15px; }
.doc-meta { text-align: center; }
}
</style>
</head>
<body>
<div class="document-container">
<header class="document-header">
<div class="header-top">
<div class="company-badge">
<div class="company-logo">فن آوران<br>ساحر علم</div>
</div>
<div class="doc-meta">
<div>شماره مستند: TECH-1405-004</div>
<div>نسخه: ۲.۰</div>
<div>تاریخ تهیه: ۲۸ مهر ۱۴۰۵</div>
<div>طبقه‌بندی: داخلی / فنی</div>
</div>
</div>
<div class="document-title">
<span class="label">DEPLOYMENT & OPTIMIZATION GUIDE</span>
<h1>مستند فنی راه‌اندازی مدل Qwen3.5-9B</h1>
<h2>پیاده‌سازی گام‌به‌گام با Llamafile و AirLLM بر روی سیستم ۶۴GB RAM / 4GB VRAM</h2>
</div>
</header>
<div class="document-body">
<div class="intro-text">
<strong>همکاران و ذینفعان محترم،</strong><br>
این مستند، نسخه به‌روزرسانی‌شده راهنمای استقرار مدل <strong>Qwen3.5-9B-The-Defiant-Fable-Uncensored-Heretic-NEO-IMATRIX-MAX-MTP-GGUF</strong> است. با توجه به درخواست‌های فنی جدید، دو مسیر پیاده‌سازی مجزا و بهینه برای سخت‌افزار هدف (۶۴ گیگابایت رم سیستم و ۴ گیگابایت حافظه گرافیکی) تشریح شده است: استفاده از <strong>Llamafile</strong> (برای اجرای مستقیم و بهینه فایل‌های GGUF) و <strong>AirLLM</strong> (برای بارگذاری لایه‌ای مدل‌های فرمت Hugging Face).
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۱</div>
<div class="section-title">
<h3>استراتژی تخصیص منابع سخت‌افزاری</h3>
<div class="subtitle">Hardware Resource Allocation Strategy</div>
</div>
</div>
<div class="section-content">
<p>با توجه به محدودیت شدید VRAM (۴ گیگابایت) و وفور RAM سیستم (۶۴ گیگابایت)، استراتژی اصلی بر پایه <strong>Offloading هیبریدی</strong> استوار است:</p>
<div class="info-box">
<strong>تحلیل حجم مدل:</strong><br>
• نسخه پیشنهادی GGUF: <code>Q4_K_M</code> یا <code>Q5_K_M</code> (حجم تقریبی: ۶.۸ تا ۷.۸ گیگابایت).<br>
• فایل پردازشگر بینایی (<code>mmproj-F16.gguf</code>): حجم تقریبی ۰.۵ تا ۱ گیگابایت.<br>
• <strong>مجموع مورد نیاز:</strong> حدود ۸ گیگابایت فضای حافظه (که به‌راحتی در ۶۴ گیگابایت RAM جای می‌گیرد).
</div>
<div class="success-box">
<strong>✅ راهکار بهینه:</strong><br>
مدل به‌صورت کامل در RAM سیستم بارگذاری می‌شود. سپس، با تنظیم دقیق پارامترهای موتور استنتاج، تعداد مشخصی از لایه‌ها (حدود ۱۵ تا ۲۰ لایه) به همراه کل فایل <code>mmproj</code> به ۴ گیگابایت VRAM منتقل می‌شوند. این کار سرعت را به‌شدت افزایش داده و از خطای Out of Memory (OOM) جلوگیری می‌کند.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۲</div>
<div class="section-title">
<h3>روش اول: پیاده‌سازی با Llamafile (پیشنهاد اصلی برای GGUF)</h3>
<div class="subtitle">Implementation via Llamafile (Recommended for GGUF)</div>
</div>
</div>
<div class="section-content">
<p>ابزار <strong>Llamafile</strong> (توسعه‌یافته توسط Mozilla) یک فایل اجرایی تک‌فایلی است که موتور <code>llama.cpp</code> و مدل را در خود جای می‌دهد. این روش ساده‌ترین، پایدارترین و بهینه‌ترین راه برای اجرای فایل‌های GGUF به‌همراه قابلیت چندوجهی (Multimodal) است.</p>
<div class="highlight-box">
<strong>گام ۱: دانلود فایل‌های ضروری</strong>
<p class="no-indent" style="margin-top: 10px;">۱. دانلود فایل اجرایی <code>llamafile</code> از مخزن رسمی Mozilla AI.<br>
۲. دانلود فایل مدل: <code>Qwen3.5-9B-...-Q4_K_M.gguf</code> (یا Q5_K_M).<br>
۳. دانلود فایل پردازشگر تصویر: <code>mmproj-F16.gguf</code> از همان مخزن Hugging Face.</p>
</div>
<div class="highlight-box">
<strong>گام ۲: تنظیم مجوزهای اجرایی (در لینوکس/مک)</strong>
<pre><code>chmod +x llamafile</code></pre>
</div>
<div class="highlight-box">
<strong>گام ۳: اجرای بهینه‌شده برای ۴ گیگابایت VRAM</strong>
<p class="no-indent" style="margin-top: 10px;">دستور زیر مدل را با استفاده از RAM سیستم اجرا کرده و دقیقاً ۱۸ لایه را به GPU منتقل می‌کند (ایمن برای ۴GB VRAM):</p>
<pre><code>./llamafile \
--model Qwen3.5-9B-The-Defiant-Fable-Q4_K_M.gguf \
--mmproj mmproj-F16.gguf \
--n-gpu-layers 18 \
--ctx-size 8192 \
--temp 0.7 \
--top-p 0.85 \
--repeat-penalty 1.0 \
--n-predict 512</code></pre>
</div>
<div class="warning-box">
<strong>⚠️ نکته حیاتی:</strong> اگر هنگام آپلود تصویر با خطای OOM مواجه شدید، مقدار <code>--n-gpu-layers</code> را به ۱۵ یا ۱۴ کاهش دهید. فایل <code>mmproj</code> به‌صورت پیش‌فرض سعی می‌کند خود را به GPU منتقل کند و نیاز به فضای رزرو شده دارد.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۳</div>
<div class="section-title">
<h3>روش دوم: پیاده‌سازی با AirLLM (مخصوص فرمت Hugging Face)</h3>
<div class="subtitle">Implementation via AirLLM (For Hugging Face Weights)</div>
</div>
</div>
<div class="section-content">
<p><strong>توضیح معماری:</strong> کتابخانه <strong>AirLLM</strong> به‌طور ذاتی برای اجرای مستقیم فایل‌های GGUF طراحی نشده است، بلکه برای بارگذاری لایه‌ای (Layer-wise) مدل‌های فرمت Hugging Face (<code>.safetensors</code> یا <code>.bin</code>) بهینه شده است. اگر قصد دارید از وزن‌های اصلی یا Fine-tune شده این مدل در فرمت HF استفاده کنید، این روش بهترین گزینه برای دور زدن محدودیت ۴ گیگابایت VRAM است.</p>
<div class="highlight-box">
<strong>گام ۱: نصب پیش‌نیازها</strong>
<pre><code>pip install airllm torch transformers</code></pre>
</div>
<div class="highlight-box">
<strong>گام ۲: اسکریپت پایتون برای بارگذاری لایه‌ای</strong>
<p class="no-indent" style="margin-top: 10px;">کد زیر به‌طور خودکار مدل را در RAM بارگذاری کرده و لایه‌ها را به‌صورت پویا به GPU منتقل می‌کند:</p>
<pre><code>from airllm import AutoModel
import torch
# شناسه مدل (مثال: نسخه پایه یا فاین‌تیون شده در فرمت HF)
# توجه: برای نسخه DavidAU، اگر مخزن HF در دسترس باشد، نام آن جایگزین شود
model_id = "Qwen/Qwen3.5-9B"
print("در حال بارگذاری مدل با استراتژی AirLLM...")
model = AutoModel.from_pretrained(
model_id,
compression=None # برای حفظ دقت کامل. در صورت نیاز به سرعت بیشتر: '4bit'
)
# توکنایزیشن ورودی
input_text = ["این تصویر را تحلیل کن و جزئیات آن را بگو."]
# نکته: برای ورودی چندوجهی در AirLLM، نیاز به پردازشگر تصویر جداگانه و الحاق Image Tokens است
input_tokens = model.tokenizer(
input_text,
return_tensors="pt",
truncation=True,
max_length=4096
)
# اجرای استنتاج
print("در حال تولید پاسخ...")
generation_output = model.generate(
input_tokens['input_ids'].cuda(),
max_new_tokens=256,
use_cache=True,
return_dict_in_generate=True
)
output = model.tokenizer.decode(generation_output.sequences[0])
print(output)
</code></pre>
</div>
<div class="info-box">
<strong>💡 مزیت AirLLM در این سخت‌افزار:</strong><br>
AirLLM به‌صورت پیش‌فرض فقط <strong>یک لایه</strong> را در هر لحظه در VRAM نگه می‌دارد. بنابراین، حتی یک مدل ۹ میلیارد پارامتری با دقت کامل (BF16) نیز به‌راحتی در ۴ گیگابایت VRAM اجرا می‌شود، زیرا کل بار محاسباتی بر روی ۶۴ گیگابایت RAM سیستم تقسیم شده و تنها نتایج میانی از GPU عبور می‌کنند.
</div>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۴</div>
<div class="section-title">
<h3>مقایسه فنی و انتخاب مسیر</h3>
<div class="subtitle">Technical Comparison & Path Selection</div>
</div>
</div>
<div class="section-content">
<table class="styled-table">
<thead>
<tr>
<th>شاخص ارزیابی</th>
<th>Llamafile (GGUF)</th>
<th>AirLLM (Hugging Face)</th>
</tr>
</thead>
<tbody>
<tr>
<td>سهولت راه‌اندازی</td>
<td style="color: var(--success); font-weight: 600;">بسیار بالا (تک‌فایل اجرایی)</td>
<td>متوسط (نیاز به محیط پایتون)</td>
</tr>
<tr>
<td>پشتیبانی چندوجهی (تصویر)</td>
<td style="color: var(--success); font-weight: 600;">عالی (با فایل mmproj)</td>
<td>پیچیده (نیاز به کدنویسی پردازش تصویر)</td>
</tr>
<tr>
<td>مدیریت ۴GB VRAM</td>
<td>خوب (با تنظیم دستی <code>-ngl</code>)</td>
<td style="color: var(--success); font-weight: 600;">عالی (لایه‌ای خودکار)</td>
</tr>
<tr>
<td>سرعت استنتاج (Tokens/sec)</td>
<td>بالا (به‌ویژه با نسخه MTP)</td>
<td>متوسط (به دلیل سربای انتقال لایه‌ها)</td>
</tr>
<tr class="highlight-row">
<td><strong>توصیه نهایی</strong></td>
<td style="color: var(--success); font-weight: 700;"><strong>انتخاب اول برای این سناریو</strong></td>
<td>انتخاب دوم (برای یکپارچه‌سازی در کد پایتون)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section">
<div class="section-header">
<div class="section-number">۵</div>
<div class="section-title">
<h3>جمع‌بندی و توصیه‌های نهایی</h3>
<div class="subtitle">Conclusion & Final Recommendations</div>
</div>
</div>
<div class="section-content">
<div class="conclusion-box">
<h3>🎯 ارزیابی نهایی معماری</h3>
<p>برای سیستم هدف با ۶۴ گیگابایت RAM و ۴ گیگابایت VRAM، استفاده از <strong>Llamafile</strong> به‌همراه فایل‌های GGUF و <code>mmproj</code>، پایدارترین و کم‌دردسرترین مسیر برای بهره‌مندی از قابلیت‌های چندوجهی و سرعت بالای مدل Qwen3.5-9B است.</p>
<p>در صورتی که نیاز به ادغام عمیق مدل در یک پایپ‌لاین پایتونی دارید، <strong>AirLLM</strong> با مکانیزم بارگذاری لایه‌ای، محدودیت VRAM را به‌طور کامل خنثی می‌کند.</p>
<div class="highlight">
<strong>💡 توصیه‌های کلیدی برای حفظ پایداری:</strong><br>
۱. در Llamafile، هرگز مقدار <code>--n-gpu-layers</code> را برای این سخت‌افزار بالاتر از ۲۰ تنظیم نکنید.<br>
۲. در هر دو روش، <code>Repetition Penalty</code> را روی ۱.۰ نگه دارید تا از اختلال در عملکرد MTP جلوگیری شود.<br>
۳. برای کارهای برنامه‌نویسی دقیق، دما (Temperature) را به ۰.۶ کاهش دهید.
</div>
</div>
</div>
</div>
<div class="page-info">
این مستند محرمانه بوده و صرفاً جهت استفاده داخلی در شرکت فن آوران ساحر علم تهیه شده است. هرگونه کپی‌برداری یا افشا بدون اجازه کتبی ممنوع است.
</div>
</div>
<footer class="document-footer">
<div class="footer-brand">طراحی و تدوین: هادی خزاعی اصل | معمار ارشد و توسعه‌دهنده سامانه‌های نرم‌افزاری</div>
<div class="footer-divider"></div>
<div>شرکت: فن آوران ساحر علم &nbsp;|&nbsp; تاریخ تهیه: ۲۸ مهر ۱۴۰۵ &nbsp;|&nbsp; نسخه: ۲.۰ &nbsp;|&nbsp; طبقه‌بندی: داخلی / فنی</div>
</footer>
</div>
</body>
</html>