[경량화 챌린지] 5일차

ehghkwl·2025년 11월 19일

Lightweight Challenge

목록 보기
5/22
  • model.generate()
    torch에서는 추론을 하려면, output = model(input) 이런식이다. 근데, transformers에서는 model.generate()라는 별도의 함수를 사용한다 (Hugging Face 전용의 편의 함수).
    왜냐면, model(input)은 딱 1글자만 예측하게끔 되어있는 시퀀스이기 떄문에, 문장의 길이를 알 수 없는 llm에서는 사용이 어렵다. (단답형, classification에서는 사용할 수 있지만.)
    반면, model.generate()는 내부적으로 model(input)을 여러번 반복해서 실행해주는 함수이기 때문에 문장 끝까지 완성이 가능해진다.
    따라서, 글, 영상, 음성과 같이 출력이 이어지는 시퀀스의 경우에만 사용한다고 생각하면 될거같다.
    • model(input)
      model("대한민국의 수도는") -> 결과 "서울"
    • model.generate()
      model("대한민국의 수도는") -> 결과 "서울"
      model("대한민국의 수도는 서울") -> 결과 "입니다"
      model("대한민국의 수도는 서울입니다") -> 결과 "."
      종료!
  • nvidia-smi 명령어
    터미널에서 GPU 사용률이나 VRAM 사용량을 확인할 수 있는 명령어
    윈도우에서는 nvidia-smi -l 1 이거 사용하면, 지속적으로 업데이트됨.
    linux는 watch -n 0.5 nvidia-smi
  • model.generate() 실행
    time.time()을 import하고, .generate() 함수 앞뒤로 start_time과 end_time을 찍어 총 실행 시간을 측정.
    내일 각 코드에서 궁금하거나 모르는 부분 추가 공부하기
    int8/int4 각각 돌려봄!
    (pruning) C:\Users\KHH\source\lab\EfficientML\LightweightChallenge>python 005_model_inference.py
    모델 로드 (int8)

Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 4/4 [00:16<00:00, 4.08s/it]
모델 로드 완료

질문: Hello, please introduce yourself briefly.
답변 생성 시작

C:\Users\KHH.conda\envs\pruning\lib\site-packages\transformers\models\llama\modeling_llama.py:602: UserWarning: 1Torch was not compiled with flash attention. (Triggered internally at C:\actions-runner_work\pytorch\pytorch\builder\windows\pytorch\aten\src\ATen\native\transformers\cuda\sdp_utils.cpp:555.)
attn_output = torch.nn.functional.scaled_dot_product_attention(
걸린 시간: 6.15초
생성된 토큰: 50개
속도 (TPS): 8.13 tokens/sec

AI 답변:
Hello, please introduce yourself briefly. I am a 27-year-old woman from Hamburg. I am a social worker and work in a women’s shelter for women in distress. I have been in a relationship with my girlfriend for 2 years. I have been in a relationship with my
메모리를 비우기
청소 완료! VRAM clear


모델 로드 (int4)

Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 4/4 [00:18<00:00, 4.75s/it]
모델 로드 완료

질문: Hello, please introduce yourself briefly.
답변 생성 시작

걸린 시간: 2.95초
생성된 토큰: 50개
속도 (TPS): 16.94 tokens/sec

AI 답변:
Hello, please introduce yourself briefly. I am an 18 year old girl from the Netherlands, and I have a big interest in music. I am a musician myself, and I love listening to music. I am very happy to be a part of this community.
What are your favorite

profile
안녕하세요.

0개의 댓글