qgon.integrations.hf
Hugging Face Transformers integration that reports Trainer progress through qgon.progress.
from qgon.integrations.hf import QgonProgressCallbacktrainer = Trainer(model, args, ..., callbacks=[QgonProgressCallback()])It reports step = state.global_step, total = state.max_steps and epoch = state.epoch. In multi-process training only the main process (world process zero) reports. If qgon.init() has been called and transformers.trainer is already imported, the callback attaches to Trainer automatically (turn this off with QGON_AUTO_PROGRESS=0). transformers is imported only when the class is first accessed; without it, you get a plain class with the same methods for tests and direct calls.
The same callback handles GPU yield, so nothing else needs to be attached. In single-process training it marks the run as able to yield. When a yield request arrives, it has Trainer save output_dir/checkpoint-N at the end of the next step, packs that folder into one tar file, uploads it with qgon.checkpoint(path=...) and exits with code 75. If saving or uploading fails, it ends at on_train_end so the run resumes from the last checkpoint. To resume, call trainer.train(resume_from_checkpoint=resume_dir()). Multi-process (distributed) training is not marked as able to yield and does not yield automatically.
import qgon.integrations.hfresume_dir
functionReturns the Hugging Face checkpoint folder path (str) for trainer.train(resume_from_checkpoint=...) when the run was started with Resume training, otherwise None; a tar checkpoint is safely extracted into dest (a temporary folder by default), rejecting absolute paths, '..' and links.
resume_dir(dest=None)Full description (Korean original)
체크포인트가 tar(양보·이 연동이 올린 것)면 dest(기본 임시 폴더)에 안전하게 풀고(절대 경로·'..'·링크 거절) 그 안의 폴더를 돌려준다.
In the app · Build › Scheduling
Trainer callback that reports progress through qgon.progress and handles GPU yield requests.
QgonProgressCallback()Full description (Korean original)
from qgon.integrations.hf import QgonProgressCallbacktrainer = Trainer(model, args, ..., callbacks=[QgonProgressCallback()])step = state.global_step, total = state.max_steps, epoch = state.epoch. 여러 프로세스(분산) 학습이면 주 프로세스(world process zero)만 쓴다.
qgon.init() 을 불렀고 transformers.trainer 가 이미 import 돼 있으면 Trainer 에 자동으로 붙는다(install_auto, 끄기: QGON_AUTO_PROGRESS=0).
transformers 는 클래스를 꺼낼 때 처음 import 한다. 없으면 같은 메서드를 가진 일반 클래스(가짜 state 로 시험·직접 호출용).
GPU 양보: 같은 콜백이 한다(따로 붙일 것 없음): 학습 시작 때 프로세스 하나(args.world_size == 1)면 '양보 가능'(qgon_yield_capable=1) 표시. 양보 요청이 오면 다음 단계 끝에 control.should_save·should_training_stop → Trainer 가 output_dir/checkpoint-N 을 저장 → on_save 에서 그 폴더를 tar 하나로 묶어 qgon.checkpoint(path=…) 로 올림 → 올린 직후 종료 75. 사용자 콜백(예: 미세조정 러너)이 on_save 에서 먼저 qgon.checkpoint 를 부르면 거기서 끝난다. 저장·업로드가 안 되면 학습 끝(on_train_end)에서 마지막 체크포인트부터 이어지도록 끝낸다. 이어서 학습: trainer.train(resume_from_checkpoint=resume_dir()), '이어서 학습'으로 시작한 실행이면 그 tar 를 풀어 폴더 경로, 아니면 None. 분산 학습(args.world_size > 1, 환경변수 WORLD_SIZE>1, torch.distributed world size>1, _yield.distributed)은 표시·자동 양보를 하지 않는다 (한 순위만 멈추면 나머지가 기다린다). tar 는 디스크 여유를 보고 임시 폴더 → 체크포인트 옆, 둘 다 모자라면 묶지 않고 끝낸다.
In the app · Build › Scheduling