[LAB 02 · 参数迁移:冻结、局部与全量微调](/course/notebooks/4bd450d54870432db91c80a4df563b8e.html) # 4. 固定选择后,再看保留集 · 实现代码 [独立阅读](/course/notebook-blocks/baa01d90e8534271a23cc4abac67a240.html) 按问题继续 同源参数的冻结/局部/全量/scratch与BN模式辨析 展开完整实现代码 ``` selected_mode=min(records,key=lambda m:records[m]['validation']['ce']) for mode,model in models.items(): records[mode]['heldout']=evaluate_binary(model,x[heldout_idx],y[heldout_idx]) print('只按验证 CE 选出的方案:',selected_mode) print('mode | train acc | val acc | heldout acc | selected epoch') for mode,r in records.items(): print(mode,round(r['train']['accuracy'],4),round(r['validation']['accuracy'],4),round(r['heldout']['accuracy'],4),r['selected_epoch']) LAB09_RESULT={'provenance':provenance,'protocol':{'train_n':TRAIN_LIMIT,'dx':DX,'epochs':EPOCHS,'batch_size':BATCH_SIZE,'learning_rate':LEARNING_RATE,'seed':SEED}, 'selected_by_validation':selected_mode,'scopes':scope_table,'records':records} print('LAB09_RESULT_JSON='+json.dumps(LAB09_RESULT,ensure_ascii=False)) (OUT/'transfer-results.json').write_text(json.dumps(LAB09_RESULT,ensure_ascii=False,indent=2)) # 当前单元无法确认宿主平台或是否使用全新进程;unknown 不等于 False。 verification={'local_run':'unknown','cloud_run':'unknown','source_model_unchanged':hashlib.sha256(MODEL_PATH.read_bytes()).hexdigest()==model_sha256,'source_checkpoint_sha256':model_sha256,'sample_split_independent':True,'selected_by_validation':selected_mode,'scope':'complete student/teacher re-execution of 4 small transfer arms','torch':torch.__version__} (OUT/'verification.json').write_text(json.dumps(verification,indent=2)) ```