Instructions to use XiangnanW/CGVM-R2.6-Qwen3VL-8B-step600 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use XiangnanW/CGVM-R2.6-Qwen3VL-8B-step600 with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Download src/scripts/gpu_job.py from XiangnanW/CGVM-R2.6-Qwen3VL-8B-step600: direct link, hf CLI and curl.
- Browser
- Download file 5.53 kB
-
https://huggingface.co/XiangnanW/CGVM-R2.6-Qwen3VL-8B-step600/resolve/main/src/scripts/gpu_job.py
- Command line
-
hf download hf://XiangnanW/CGVM-R2.6-Qwen3VL-8B-step600/src/scripts/gpu_job.py
-
curl -L -o gpu_job.py https://huggingface.co/XiangnanW/CGVM-R2.6-Qwen3VL-8B-step600/resolve/main/src/scripts/gpu_job.py
5.53 kB
| #!/usr/bin/env python3 | |
| """四卡重型作业的持久串行入口;检查授权卡空闲,不触碰其他用户进程。""" | |
| import argparse | |
| import fcntl | |
| import json | |
| import os | |
| from pathlib import Path | |
| import subprocess | |
| import resource | |
| import sys | |
| import time | |
| ROOT=Path(__file__).resolve().parents[1] | |
| sys.path.insert(0,str(ROOT/'scripts')) | |
| from download_assets import atomic, safe_flock | |
| if __name__=='__main__': | |
| parser=argparse.ArgumentParser();parser.add_argument('--name',required=True);parser.add_argument('script');parser.add_argument('arguments',nargs=argparse.REMAINDER);args=parser.parse_args() | |
| script=(ROOT/args.script).resolve() | |
| if not script.is_relative_to(ROOT/'scripts') or not script.is_file():raise ValueError('只运行本项目已保存脚本') | |
| name=args.name | |
| if any(c not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_' for c in name):raise ValueError('作业名称非法') | |
| if script.name in ('train_reader.py','train_retrieval.py'): | |
| if '--variant' not in args.arguments:raise ValueError('训练需要显式variant') | |
| variant=args.arguments[args.arguments.index('--variant')+1] | |
| if variant=='R2': | |
| stage='reader' if script.name=='train_reader.py' else 'retrieval' | |
| formal=script.name=='train_retrieval.py' or '--mode' not in args.arguments or args.arguments[args.arguments.index('--mode')+1]=='formal' | |
| if formal: | |
| proof=json.loads((ROOT/'checkpoints/R1'/stage/'exact_epoch_audit.json').read_text()) | |
| if not proof.get('passed'):raise RuntimeError('正式R2必须在R1相应阶段完成后串行执行') | |
| (ROOT/'coordination').mkdir(parents=True,exist_ok=True) | |
| (ROOT/'logs').mkdir(parents=True,exist_ok=True) | |
| lock_path=ROOT/'coordination/gpu.lock' | |
| if not lock_path.exists():lock_path.write_text('') | |
| atomic(ROOT/'coordination'/('job-'+name+'.json'),dict(status='waiting_gpu_lock',supervisor_pid=os.getpid(),script=str(script),arguments=args.arguments,updated_at=time.time())) | |
| with lock_path.open('r+') as lock: | |
| safe_flock(lock,fcntl.LOCK_EX) | |
| vis_env=os.environ.get('CUDA_VISIBLE_DEVICES','').strip() | |
| while True: | |
| lines=subprocess.check_output(['nvidia-smi','--query-gpu=index,memory.used,memory.total','--format=csv,noheader,nounits'],text=True).splitlines() | |
| parsed=[(int(p[0].strip()),int(p[1].strip()),int(p[2].strip())) for p in (line.split(',') for line in lines if line.strip())] | |
| if vis_env: | |
| target_gpus=[int(x.strip()) for x in vis_env.split(',') if x.strip()] | |
| else: | |
| target_gpus=[idx for idx,_,_ in parsed] | |
| busy=[(idx,used) for idx,used,_ in parsed if idx in target_gpus and used>512] | |
| if not busy:break | |
| print('目标GPU被占用,等待并保留其他进程',busy,flush=True);time.sleep(30) | |
| lock.seek(0);lock.truncate();lock.write(str(os.getpid()));lock.flush() | |
| vis_str=','.join(str(i) for i in target_gpus) | |
| max_vram_mib=max((tot for idx,_,tot in parsed if idx in target_gpus),default=80000) | |
| num_gpus=len(target_gpus) | |
| if 'CGVM_NPROC_PER_NODE' in os.environ: | |
| nproc=int(os.environ['CGVM_NPROC_PER_NODE']) | |
| elif script.name in ('cache_causal_memory.py','cache_writer_memory.py') and max_vram_mib>=140000: | |
| default_w='4' if max_vram_mib>=240000 else '2' | |
| workers_per_gpu=int(os.environ.get('CGVM_CACHE_WORKERS_PER_GPU',default_w)) | |
| nproc=num_gpus*workers_per_gpu | |
| else: | |
| nproc=num_gpus | |
| python_bin=str(ROOT/'.venv/bin/torchrun') if (ROOT/'.venv/bin/torchrun').exists() else 'torchrun' | |
| command=[python_bin,'--standalone',f'--nproc_per_node={nproc}',str(script),*args.arguments] | |
| environment=dict(os.environ,CUDA_VISIBLE_DEVICES=vis_str,OMP_NUM_THREADS='4',TOKENIZERS_PARALLELISM='false',HF_HUB_OFFLINE=os.environ.get('HF_HUB_OFFLINE','1')) | |
| with (ROOT/'logs'/(name+'.log')).open('a') as logfile: | |
| resources_before=resource.getrusage(resource.RUSAGE_CHILDREN) | |
| child=subprocess.Popen(command,cwd=ROOT,env=environment,stdout=logfile,stderr=subprocess.STDOUT) | |
| value=dict(status='running',supervisor_pid=os.getpid(),torchrun_pid=child.pid,command=command, | |
| CUDA_VISIBLE_DEVICES=vis_str,nproc_per_node=nproc,started_at=time.time()) | |
| atomic(ROOT/'coordination'/('job-'+name+'.json'),value) | |
| with (ROOT/'logs/gpu_jobs.jsonl').open('a') as journal: | |
| journal.write(json.dumps(dict(value,event='started',name=name))+'\n') | |
| atomic(ROOT/'coordination/stage.json',dict(stage=name,updated_at=time.time())) | |
| result=child.wait() | |
| value.update(status='process_exited_successfully_validation_still_required' if result==0 else 'failed',returncode=result,finished_at=time.time()) | |
| resources_after=resource.getrusage(resource.RUSAGE_CHILDREN) | |
| value.update(reserved_GPU_seconds=num_gpus*(value['finished_at']-value['started_at']), | |
| child_user_CPU_seconds=resources_after.ru_utime-resources_before.ru_utime, | |
| child_system_CPU_seconds=resources_after.ru_stime-resources_before.ru_stime) | |
| atomic(ROOT/'coordination'/('job-'+name+'.json'),value) | |
| with (ROOT/'logs/gpu_jobs.jsonl').open('a') as journal: | |
| journal.write(json.dumps(dict(value,event='exited',name=name))+'\n') | |
| raise SystemExit(result) | |