Download code/scripts/finalize_report.py from CollinMa/nextgpt-chapter6-report: direct link, hf CLI and curl.
- Browser
- Download file 7.52 kB
-
https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/finalize_report.py
- Command line
-
hf download hf://spaces/CollinMa/nextgpt-chapter6-report/code/scripts/finalize_report.py
-
curl -L -o finalize_report.py https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/resolve/main/code/scripts/finalize_report.py
7.52 kB
| """Summarize only actual recorded executions and prepare the submission archive.""" | |
| import json | |
| import re | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0,str(ROOT)) | |
| from settings import OUTPUTS, UPSTREAM_COMMIT | |
| def finalize(): | |
| destination = ROOT/'docs'/'execution' | |
| destination.mkdir(exist_ok=True) | |
| for name in ('first_inference','course_cases','merge_vicuna','image_qa_fixed','image_qa_examples','image_qa_car'): | |
| log = ROOT/'logs'/(name+'.txt') | |
| if log.exists(): | |
| text = log.read_text(encoding='utf-8',errors='replace').replace(str(ROOT),'.') | |
| text = re.sub(r'hf_[A-Za-z0-9]{20,}','[REDACTED]',text) | |
| (destination/(name+'-output.txt')).write_text(text,encoding='utf-8') | |
| runs = [json.loads(p.read_text(encoding='utf-8')) for p in sorted(OUTPUTS.glob('*/run.json'))] if OUTPUTS.exists() else [] | |
| evaluations = sorted(OUTPUTS.glob('evaluation-*.json')) if OUTPUTS.exists() else [] | |
| cases = json.loads(evaluations[-1].read_text(encoding='utf-8')) if evaluations else [] | |
| success = [r for r in runs if r.get('status')=='success'] | |
| runs.sort(key=lambda r:r.get('started_at','')) | |
| report = ['# NExT-GPT 课程作业复现报告','', | |
| '## 提交方式','', | |
| '依据老师补充要求,无法部署 GPU Space 时提交代码与实际执行结果。本项目保持零付费。免费 Static Space 仅展示报告、源码和结果,不提供在线模型推理。','', | |
| '报告链接:https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report','', | |
| '源码链接:https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/tree/main/code','', | |
| '## 实现与环境','', | |
| f'官方 NExT-GPT Legacy,提交 {UPSTREAM_COMMIT}。使用 LLaMA 7B + LMSYS Vicuna v0 delta 恢复基座,再加载官方 7b_tiva_v0 增量参数和 ImageBind。未用其他模型替代、未重新训练。','', | |
| '本地 RTX 4060 Laptop 8GB、32GB 系统内存;Python 3.10 / PyTorch 1.13.1+cu117。LLM 与 ImageBind 参数使用 CPU 卸载,解码器按需加载并使用切片,保持 FP16 参数。','', | |
| '## 实际执行结果','', | |
| f'记录到 {len(runs)} 次完整模型调用,其中程序执行成功 {len(success)} 次。成功不等同于所有要求的模态都已生成或内容完全正确。',''] | |
| report += ['## 本次范围与人工检查','', | |
| '当前交付范围为官方 NExT-GPT 7B 的“图片+文字指令→文字回答”推理复现。四模态内容生成及重新训练不在本次已验证范围内。','', | |
| '人工检查:狗图片的简短类别回答与汽车图片的类别回答均与输入主体一致。狗图片的较详细描述臆测了“蓝色飞盘”,原图没有飞盘,记录为内容幻觉。早期输出有多余 # 分隔符,停止条件已修复,旧记录仍保留。该少量样例不代表基准准确率。',''] | |
| report += ['## 本地复现方法','', | |
| '按 README 安装 Python 3.10 与固定依赖,准备 LLaMA、Vicuna delta、ImageBind、NExT-GPT 权重并恢复 Vicuna。提交包不含数十 GB 权重和本机环境;同机已有权重可直接复用。','', | |
| '```powershell', | |
| 'python scripts/run_local_gpu.py --image examples/inputs/car_image.jpg --prompt "What object is shown in this image? Answer briefly."', | |
| '```','', | |
| '结果保存到 outputs/<运行ID>/run.json、response.txt 和 raw-response.txt。当前文字回答模式不下载扩散解码器。首次加载耗时未计入下述每次生成耗时;结果时间戳采用 UTC。',''] | |
| if not success: | |
| report += ['**尚无成功的完整 7B 模型推理结果,作业复现尚未完成。** 环境、fixture 测试和权重准备不能替代该结果。',''] | |
| component=ROOT/'docs/execution/imagebind-component-result.json' | |
| if component.is_file(): | |
| item=json.loads(component.read_text(encoding='utf-8')) | |
| report += ['### 已完成的编码器组件验证','', | |
| '使用真实预训练 ImageBind 权重,在本机 GPU 上处理公开的狗图片和三个候选文字标签。最高分标签:'+item['top_prompt']+'。', | |
| '三个候选标签的 softmax 分数:'+str(item['scores'])+'。', | |
| '耗时(含加载):'+str(item['elapsed_seconds'])+' 秒;该结果仅验证编码器,不是完整 7B 模型输出。',''] | |
| for record in runs: | |
| report += [f"### {record.get('started_at','未记录时间')}",'', | |
| '状态:'+record.get('status','unknown'),'', | |
| '提示词:'+record.get('prompt',''),'', | |
| '实际文字:','', '```text',record.get('text',record.get('error','无')),'```','', | |
| f"耗时:{record.get('elapsed_seconds','未测量')} 秒;PyTorch 峰值已分配显存:{record.get('peak_gpu_gib','未测量')} GiB(非整卡总占用)。",''] | |
| report += ['## 尚未验证的扩展案例','', '| 案例 | 期望输出 | 实际状态 |','| --- | --- | --- |'] | |
| for case in cases: | |
| report.append(f"| {case['id']} | {case['expected_output']} | {case['status']} |") | |
| if not cases: | |
| report.append('| 四组案例 | T+A / T+I+V / T+I+V+A | 未运行 |') | |
| report += ['', '原始记录保存在压缩包的 submission_results 中。生成内容的质量需人工检查。测试图片和音频来自 Meta ImageBind 官方公开样例;dog_zoom.mp4 是由静态图片合成的输入片段,不是模型生成结果。','', | |
| '## 限制','', | |
| '本机低显存卸载会增加传输时间。案例若只产生部分模态,应标记为 partial;失败日志如实保留。Static Space 不执行模型,因此不能声称完成在线模型部署。',''] | |
| (ROOT/'docs'/'REPORT.md').write_text('\n'.join(report),encoding='utf-8') | |
| if success: | |
| readme=ROOT/'README.md' | |
| content=readme.read_text(encoding='utf-8') | |
| content=re.sub(r'\*\*当前状态:.*?\*\*','**当前状态:已跑通官方 7B 模型的图片→文字问答,原始输入、输出、失败记录与幻觉样例已保留。未验证四模态生成,未重新训练。**',content,count=1,flags=re.S) | |
| content=content.replace('当前完整运行结果仍未生成。','图片问答结果见 docs/REPORT.md 和提交包的 submission_results。') | |
| content=content.replace('完整 7B 案例尚待实测。','完整 7B 图片问答已实测,其他模态组合尚未验证。') | |
| readme.write_text(content,encoding='utf-8') | |
| summary = {'full_model_runs':len(runs),'successful_runs':len(success),'course_cases':cases} | |
| (destination/'model-execution-summary.json').write_text(json.dumps(summary,ensure_ascii=False,indent=2),encoding='utf-8') | |
| (ROOT/'docs'/'SUBMISSION.txt').write_text('NExT-GPT 作业提交说明\n\n范围:官方7B模型图片问答推理复现;未重新训练,未验证四模态生成。\n方式:按老师补充要求提交代码与实际执行结果。\n\n报告:https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report\n源码:https://huggingface.co/spaces/CollinMa/nextgpt-chapter6-report/tree/main/code\n\n重点文件:docs/REPORT.md;docs/execution/;submission_results/;examples/inputs/。\n静态Space用于展示报告和下载文件,不提供在线推理。\n已如实保留失败日志和内容幻觉样例。\n',encoding='utf-8') | |
| print(json.dumps(summary,ensure_ascii=False)) | |
| if __name__=='__main__': | |
| finalize() | |