** 이 글은 Python Debugging 기준이다.
https://code.visualstudio.com/docs/python/debugging
Debugging configurations for Python apps in Visual Studio Code
Details on configuring the Visual Studio Code debugger for different Python applications.
code.visualstudio.com
위의 링크를 참조 가능.
VScode debug configuration 파일 작성하는 방법
vscode 를 키면 좌상단에 이렇게 디버깅을 할 수 있는 것을 확인할 수 있다.
위의 플레이 버튼에서 원하는 configuration file 을 선택하고 새로 작성할 수 있다.
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
},
처음에 VScode 의 debugging configuration 을 만들면 위와 같은 디폴트 json 이 생기는 것을 확인할 수 있다.
- "name" 은 vscode configuration 이름이다.
- "type" 은 어떤 디버거 타입을 사용할지를 결정한다. 보통 'debugpy' 를 쓰는데 python 디버깅을 하기 때문이다.
- "request" 는 'launch' 는 "program" 에서 지정된 파일을 디버깅할 수 있도록 한다.
- 또 다른 option 으로는 'attach' 가 있는데 이는 이미 실행하고 있는 process 를 디버깅할 수 있다고 한다.
- "program" 은 내가 디버깅하려는 파이썬 파일을 지정할 수 있다. 위와 같이 표기하면 현재 파일을 기준으로
- "console" : 디폴트 옵션이 'integratedTerminal' 이다. program output 을 보여주는 방법이다.
- "justMyCode" 는 필자가 추가한 옵션인데, 원래 디폴트값은 true 이다.
- True 는 내가 작성한 코드 내에서만 디버깅할 수 있는 옵션이다. 만약 사용하는 라이브러리 안을 확인하고 싶으면 false 해주어야 한다.
예시 1 : Deepspeed 사용
{
"name": "Debug: ds_train",
"type": "debugpy",
"request": "launch",
"program": "/home/ubuntu/miniforge3/envs/fctrain/bin/deepspeed",
// "module":"deepspeed",
"justMyCode": false,
"console": "integratedTerminal",
"args": [
"--num_nodes=1",
"--num_gpus=4",
"fastchat/train/train_lora.py",
"--deepspeed",
"deepspeed_config.json",
"--model_name_or_path",
"/llama3",
"--num_train_epochs", "5",
],
},
- 주석처리한 부분은 "module" 인데, 디버깅할 모듈을 나타낸다.
- module 이랑 program 은 동시에 못쓴다.
- args 는 파이썬 프로그램 arguments 를 리스트 형태로 전달한다.
예시2 : Accelerate 사용
{
"name": "accelerate train",
"type": "debugpy", //"python"
"request": "launch",
"module": "accelerate.commands.launch",
"console": "integratedTerminal",
"justMyCode":false
// "env": {"CUDA_LAUNCH_BLOCKING": "1"}
"args": [
"--debug",
"train_moe.py",
"--epoch",
"2"
], // other args comes after train.py
},
'머신러닝 이모저모' 카테고리의 다른 글
Softmax Overflow 와 Underflow 문제 (0) | 2024.11.19 |
---|---|
cuda downgrade 하기 (4) | 2024.11.08 |
DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts Language Models (0) | 2024.11.07 |
Peft save_pretrained() 에러 : UnboundLocalError: local variable 'active_adapters' referenced before assignment (0) | 2024.10.20 |
[이화여대 강의] 2. Deep Learning Software Stack 1 (3) (3) | 2024.09.21 |