#!/usr/bin/env python3 """Prepare a NEW environment from observed version constraints; default dry-run. Never modifies the original training environments. GPU source builds require a matching CUDA toolkit, not merely a CUDA-capable driver/runtime wheel. """ import argparse,json,os,subprocess,sys from pathlib import Path ROOT=Path(__file__).absolute().parents[1] PROFILES={'egoexo-generator':'egoexo/generator','egoexo-captioner-phiseg':'egoexo/captioner_and_phiseg','robot-sft-grpo':'robot/legacy_sft_grpo','robot-data-cpu':'robot/data_cpu'} def main(): p=argparse.ArgumentParser(description=__doc__);p.add_argument('--profile',choices=PROFILES,required=True);p.add_argument('--prefix',type=Path,required=True);p.add_argument('--python',default=sys.executable);p.add_argument('--cuda-home',type=Path);p.add_argument('--execute',action='store_true');p.add_argument('--flash-attn',action='store_true');a=p.parse_args() folder=ROOT/PROFILES[a.profile];snap=json.loads((folder/'environment.snapshot.json').read_text());version=snap['python'];gpu=a.profile!='robot-data-cpu' cuda='cu128' if a.profile=='egoexo-captioner-phiseg' else 'cu130' commands=[[a.python,'-m','venv',str(a.prefix)], [str(a.prefix/'bin/python'),'-m','pip','install','pip','setuptools','wheel','packaging','ninja']] if a.profile=='robot-data-cpu' and (folder/'requirements.install.lock.txt').exists(): commands.append([str(a.prefix/'bin/python'),'-m','pip','install','--require-hashes','-r',str(folder/'requirements.install.lock.txt')]) else: commands.append([str(a.prefix/'bin/python'),'-m','pip','install','-r',str(folder/'requirements.core.in'),'-c',str(folder/'requirements.observed-full.lock.txt'),'--index-url','https://pypi.org/simple','--extra-index-url','https://download.pytorch.org/whl/'+cuda]) if a.profile.startswith('egoexo'): commands.append([str(a.prefix/'bin/python'),'-m','pip','install','decord==0.6.0']) if a.flash_attn: if a.profile!='robot-sft-grpo':raise ValueError('This exact flash-attn pin belongs to the robot torch2.11/cu130 profile') commands.append([str(a.prefix/'bin/python'),'-m','pip','install','--no-build-isolation','flash-attn==2.8.3']) print(json.dumps({'profile':a.profile,'required_python':version,'cuda_wheel_track':cuda if gpu else 'CPU only', 'commands':commands,'execute':a.execute,'original_environment_modified':False, 'fresh_GPU_install_and_8GPU_training_previously_verified':False},indent=2)) if not a.execute:return current=subprocess.check_output([a.python,'-c','import platform;print(platform.python_version())'],text=True).strip() if current!=version:raise ValueError('Interpreter must match captured Python '+version+'; create/select it explicitly before running this installer') if a.prefix.exists():raise ValueError('Prefix already exists; refusing to modify an existing environment') env={**os.environ,'PYTHONDONTWRITEBYTECODE':'1','MAX_JOBS':os.environ.get('MAX_JOBS','4'),'DS_BUILD_OPS':'0'} if a.cuda_home:env['CUDA_HOME']=str(a.cuda_home);env['PATH']=str(a.cuda_home/'bin')+':'+env.get('PATH','') if a.flash_attn and not a.cuda_home:raise ValueError('FlashAttention source build needs --cuda-home pointing to a CUDA13 toolkit matching torch cu130') for command in commands:subprocess.run(command,env=env,check=True) print('Installed role-specific pinned dependencies. Run verify_environment.py before training; optional source dependencies are specified in SOURCE_LOCK.json.') if __name__=='__main__':main()