File size: 6,875 Bytes
15c46ce 2c2701e 15c46ce 2c2701e 15c46ce 2c2701e 15c46ce 2c2701e 15c46ce 1c9b5b6 15c46ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | """Build an honest static report; never present it as online model inference."""
import html
import json
import shutil
import sys
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from settings import OUTPUTS
from publish_space import source_files
def build():
site = ROOT / "_report_site"
site.mkdir(exist_ok=True)
runs = []
for record_file in sorted(OUTPUTS.glob("*/run.json")) if OUTPUTS.exists() else []:
record = json.loads(record_file.read_text(encoding="utf-8"))
run_id = record_file.parent.name
target = site / "results" / run_id
target.mkdir(parents=True, exist_ok=True)
links = []
for file in record_file.parent.iterdir():
if file.is_file() and file.suffix in (".json", ".txt", ".png", ".wav", ".mp4"):
shutil.copyfile(file, target / file.name)
links.append((file.name, f"results/{run_id}/{file.name}"))
runs.append((record, links))
runs.sort(key=lambda item: item[0].get('started_at', ''))
cards = []
for record, links in runs:
media = []
for name, url in links:
escaped = html.escape(url, quote=True)
if name.endswith(".png"):
media.append(f'<img src="{escaped}" alt="模型实际生成图片">')
elif name.endswith(".mp4"):
media.append(f'<video src="{escaped}" controls></video>')
elif name.endswith(".wav"):
media.append(f'<audio src="{escaped}" controls></audio>')
media.append(f'<p><a href="{escaped}">{html.escape(name)}</a></p>')
for value in record.get('input_files',{}).values():
source=value.get('file','')
if source.startswith('examples/inputs/') and source.endswith(('.jpg','.png')):
media.insert(0,'<p>实际输入图片:</p><img src="code/'+html.escape(source,quote=True)+'" alt="实际输入图片">')
cards.append('<section><h2>实际执行记录</h2><p>状态:'+html.escape(record['status'])+
'</p><p>提示词:'+html.escape(record.get('prompt',''))+
'</p><pre>'+html.escape(record.get('text',record.get('error','')))+
'</pre><p>耗时:'+str(record.get('elapsed_seconds','未测量'))+' 秒;PyTorch 峰值已分配显存:'+
str(record.get('peak_gpu_gib','未测量'))+' GiB(非整卡总占用;耗时不含模型首次加载)</p>'+''.join(media)+'</section>')
files = source_files()
with zipfile.ZipFile(site/'nextgpt-source-and-results.zip', 'w', compression=zipfile.ZIP_DEFLATED) as archive:
for file in files:
archive.write(file, 'nextgpt-reproduction/'+file.relative_to(ROOT).as_posix())
for _, links in runs:
for _, relative in links:
archive.write(site/relative, 'nextgpt-reproduction/submission_results/'+relative)
code = site/'code'
for file in files:
destination = code/file.relative_to(ROOT)
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(file, destination)
content = '''<!doctype html><html lang="zh-CN"><meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1"><title>NExT-GPT 课程复现报告</title>
<style>body{font-family:system-ui,sans-serif;max-width:960px;margin:40px auto;padding:0 24px;color:#172338;background:#f6f8fb;line-height:1.8}section{background:white;border:1px solid #dce3ec;padding:24px;margin:24px 0;border-radius:12px}h1{font-size:30px}h2{font-size:21px}a{color:#1559b2}pre{white-space:pre-wrap;overflow-wrap:anywhere;background:#eef3f8;padding:16px}img,video{max-width:100%;max-height:540px}audio{width:100%}.note{padding:16px;background:#fff4d9;border-left:4px solid #d9a627}@media print{body{background:white;margin:0}section{break-inside:avoid}}</style>
<h1>NExT-GPT 多模态课程复现</h1>
<p class="note">本页为静态报告、源码和实际执行结果展示,不提供在线模型推理。按用户提供的老师补充说明,无法部署 GPU Space 时可提交代码与执行结果文件。</p>
<section><h2>项目与下载</h2><p>官方 NExT-GPT 7b_tiva_v0,Vicuna v0 基座;本地采用 CPU 参数卸载以适配 8GB GPU,没有用其他模型替代。</p>
<p>本次验证范围:原版 7B 模型的图片问答;未验证四模态生成,未重新训练。狗与汽车的类别回答正确,但较详细的狗描述出现了原图不存在的“蓝色飞盘”,这是已观察到的内容幻觉。失败记录和原始输出均保留。</p>
<p><a href="nextgpt-source-and-results.zip">下载源码及执行结果</a> · <a href="code/README.md">运行说明</a> · <a href="code/docs/REPORT.md">复现报告</a> · <a href="code/docs/VALIDATION.md">验证记录</a></p>
<p>权重来源:<a href="https://huggingface.co/huggyllama/llama-7b">LLaMA 7B</a>、<a href="https://huggingface.co/lmsys/vicuna-7b-delta-v0">Vicuna v0 delta</a>、<a href="https://huggingface.co/ChocoWu/nextgpt_7b_tiva_v0">NExT-GPT delta</a>。</p></section>
'''
component=ROOT/'docs/execution/imagebind-component-result.json'
if component.is_file():
evidence=json.loads(component.read_text(encoding='utf-8'))
rows=''.join('<li>'+html.escape(label)+':'+str(round(score,7))+'</li>'
for label,score in zip(evidence['prompts'],evidence['scores']))
content+='<section><h2>已执行:ImageBind 编码器组件验证</h2><p>这是 NExT-GPT 使用的预训练编码器组件,不能替代完整 7B 多模态模型推理。</p><img src="code/examples/inputs/dog_image.jpg" alt="公开的测试输入图片"><p>三个候选标签的 softmax 分数:</p><ul>'+rows+'</ul><p>耗时 '+str(evidence['elapsed_seconds'])+' 秒(含加载)。</p><a href="code/docs/execution/imagebind-component-result.json">下载原始执行记录</a></section>'
content += ''.join(cards) if cards else '<section><h2>完整 NExT-GPT 推理状态</h2><p>尚无完整 7B 模型执行记录。组件和基础检查不能替代该结果。</p></section>'
content += '<p>执行成功仅表示程序完成;生成内容质量与模态完整性需结合原始记录检查。</p></html>'
(site/'index.html').write_text(content, encoding='utf-8')
(site/'README.md').write_text('---\ntitle: NExT-GPT Course Report\nemoji: 📘\ncolorFrom: blue\ncolorTo: indigo\nsdk: static\napp_file: index.html\n---\n\nStatic reproduction report and actual execution results. No online model inference.\n', encoding='utf-8')
(site/'provenance.json').write_text(json.dumps({'project':'nextgpt-chapter6-static-report'}))
print(json.dumps({'site':str(site),'recorded_model_runs':len(runs)}))
return site
if __name__ == '__main__':
build()
|