본문 바로가기

전체 글124

[LLM][기초] LLM의 Pre-Training Objective (Full, Prefix, Masked, Unified) LLM Pre-Training ObjectiveLLM의 Pre-training objective는 크게 아래 4가지 유형으로 나눌 수 있습니다. 1. Full Language Modeling이미 주어진 token을 가지고 미래의 token들을 예측하도록 하는 auto-regressive langue model objective입니다. 2. Prefix Language Modelingprefix는 random하게 선택되고, 남아있는 target token 만으로 loss를 계산합니다. 3. Masked Language Modeling토큰 또는 연속 토큰들이 random하게 마스킹 처리 되었을 때, 모델은 과거와 미래의 컨텍스트를 가지고 마스킹된 토큰을 예측하도록 학습됩니다. 4. Unified Langua.. 2024. 9. 11.
[LLM][기초] LLM의 Layer Normalization (PreNorm, DeepNorm) Layer Normalization이란?Layer Normalization은 트랜스포머에서 각 layer의 입력값을 정규화함으로써 학습 중인 파라미터가 빠르고 안정적으로 수렴하도록 해주는 방법입니다.  LLM에서는 기본적인 Layer Norm과 RMSNorm, 외에 pre-layer normalization을 멀티 헤드 어텐션 전에 적용합니다. 그 외에 LLM에서 사용하는 normalization은 PreNorm과 DeepNorm이 있습니다. 1) PreNorm : LLM에서 학습의 안정성을 높이는 방법으로 알려짐2) DeepNorm : pre-norm에서 gradient가 증가하는 이슈를 수정한 방법론  참고https://arxiv.org/pdf/2307.06435 2024. 9. 11.
[LLM][기초] LLM의 Attention (self, cross, sparse flash) 1. Attention의 역할?Attention은 중요도에 따라서 입력된 토큰에 가중치를 부여함으로써, 모델이 연관이 있는 토큰을 더 강조할 수 있도록 합니다. 트랜스포머의 Attention은 입력 시퀀스의 query, key, value를 계산한 후, query와 key를 곱해서 attention score를 얻습니다. attention score는 value를 에 가중치를 부여하는데 사용됩니다.  2. Attention 유형1) Self Attention : encoder 혹은 decoder의 같은 block으로부터 query, key, value를 사용하여 attention을 계산2) Cross Attention : encoder-decoder 아키텍처에서 사용되는 방법으로, encoder가 out.. 2024. 9. 11.
[LLM][기초] LLM의 Positional Encoding (absolute, relative, learned) 1. Positional Encoding이 필요한 이유?기본적으로 Transformer 모델은(1) 입력 시퀀스를 병렬적이면서 독립적으로 처리하고(2) 어텐션 모듈은 위치 정보를 잡아낼 수 없기 때문에단어의 순서에 따라서 달라지는 의미를 구분할 수 없습니다.즉, 아래 두 입력 시퀀스의 차이를 구분할 수 없습니다."The dog chased the pig""The pig chased the dog"따라서, 위치 정보를 추가해주는 Positional Encoding 작업이 필요합니다.즉, 아래 그림에서dog에 해당하는 단어 임베딩에2번째 위치를 의미하는 위치 임베딩을 넣어주는 작업을 진행합니다.이때, 위치 정보를 어떤 식으로 만들어내느냐에 따라 아래 2가지 유형으로 구분됩니다.2. Positional Enc.. 2024. 9. 11.
[에러] ImportError: cannot import name 'SAVE_STATE_WARNING' from 'torch.optim.lr_scheduler' pip install torch==1.4.0 ImportError: cannot import name 'SAVE_STATE_WARNING' from 'torch.optim.lr_scheduler' Torch 1.4.0 이후 버전에서 SAVE_STATE_WARNING 모듈이 삭제되어 발생한 오류 pip install torch==1.4.0 2023. 5. 12.
[에러] packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11' packaging.version.InvalidVersion: Invalid version: '0.10.1, 2023. 5. 12.
[에러] ModuleNotFoundError: No module named 'transformers.tokenization_bert' ModuleNotFoundError: No module named 'transformers.tokenization_bert' from transformers.tokenization_bert import BasicTokenizer ModuleNotFoundError: No module named 'transformers.tokenization_bert' transformers version을 2.9에서 4.27로 upgrade하니 위와 같은 에러 발생. 구글링하니, 4.0 이상의 버전에서 발생한다고 하여 3.5로 install 후 해결 pip install transformers==3.5 https://stackoverflow.com/questions/74005930/loss-does-not-decreas.. 2023. 5. 12.
[에러] OSError: Can't load config for 'klue/bert-base' OSError: Can't load config for 'klue/bert-base'. Make sure that: - 'klue/bert-base' is a correct model identifier listed on 'https://huggingface.co/models' - or 'klue/bert-base' is the correct path to a directory containing a config.json file 아래 늘 실행하던 간단한 코드를 실행하는데, 에러가 발생했다. from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained("klue/bert-base") 혹시, transformers가 ver.. 2023. 5. 12.
[에러] AttributeError: module 'torch.distributed' has no attribute '_reduce_scatter_base' pip install torch==1.10 AttributeError: module 'torch.distributed' has no attribute '_reduce_scatter_base' python 파일을 실행하는데, 아래 부분에서 위의 에러가 났다. from transformers import ( MODEL_MAPPING, AutoConfig, AutoTokenizer, AutoModel, ) apex라는 패키지의 mapping.py에서 발생하는데, apex-0.1-py3.7.egg 파일 내에 있어서 쉽게 수정이 어려웠다. 구글링을 해보니, torch >=1.10 이어야 지원가능하다는 것 확인. https://github.com/hpcaitech/ColossalAI/issues/2673#issue.. 2023. 5. 12.
[INTRO] 프롬프트 러닝(Prompt Learning) 이란? "Prompt Learning" prompt learning이란 자연어처리 분야에서 최근 새롭게 등장한 분야로, ChatGPT의 등장과 함께 새로운 트렌드로 떠오르고 있습니다. 4월 2일자 기사에 따르면, 글로벌 교육 플랫폼 '유데미'에선 프롬프트 강의만 7667개에 달하고, 한글자막을 제공하는 콘텐츠에는 1000명씩 수강자가 이어지고 있다고 합니다. 그 외에도 프롬프트 전문 기업과 프롬프트 엔지니어라는 직종까지 생겨나고 있는데요. ✔ 'prompt'의 의미 프롬프트(prompt)라는 것은 언어모델에 전달하는 질문이나 요청을 사용자가 응답을 유도(prompt)한다는 의미에서 프롬프트(prompt)라고 합니다. 자연어 질문, 코드 스니펫, 명령어 등을 프롬프트로 사용할 수 있는데, 언어모델이 정확하게 태스.. 2023. 4. 24.
[Docker][NVIDIA] Failed to initialize NVML: Driver/library version mismatch 해결 서버 재부팅 하지않고, nvidia 프로시저 재시작으로 해결하는 방법 nvidia-smi docker에서 컨테이너를 --gpus all 옵션으로 실행하고자 하는데 아래 에러 발생 docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running hook #0: error running hook: exit status 1, stdout: , stderr: Auto-detected mode as 'legacy' nvidia-container.. 2023. 4. 19.
[Python] 파이썬 파일, 경로 복사 shutil.copyfile, copy, copy2, copytree copyfile < copy < copy2 src dst 설명 shutil.copyfile 파일 파일, 폴더 shutil.copy 이전 버전 shutil.copy 파일 파일, 폴더 shutil.copy2 파일 파일, 폴더 shutil.copy + 메타정보까지 복사 shutil.copytree 폴더 폴더 폴더 통째로 복사 2023. 1. 19.
[논문리뷰] Fine-grained Post-training for Improving Retrieval-based Dialogue Systems. NAACL 2021 Fine-grained Post-training for Improving Retrieval-based Dialogue Systems[저자] Janghoon Han(Department of Computer Science and Engineering- Sogang University, LG AI Research), Taesuk Hong, Byoungjae Kim, Youngjoong Ko, and Jungyun Seo[게재] NAACL, 2021 June [pdf][인용수] 26회인용[요약] 대화 응답 선택 (Conversational Response Selection) 태스크의 대표 3가지 데이터셋(Ubuntu, Duoban, E-commerce)에서 아래 2가지를 적용한 'fine-grained post.. 2023. 1. 18.
[Python] 파이썬 경로 제외한 파일명 반환 - os.path.basename(path) os.path.basename(path) : 상위 경로를 제외한 파일명만 반환 : "/"문자열 기준 split하여 가장 마지막 것을 반환한다고 생각하면 된다. (따라서, "/"로 끝나는 경우 빈값 반환) 1) path 가 폴더인 경우 : 폴더명 2) path 가 파일인 경우 : 파일명 import os path = "/d/workspace/dir1/dir2/dir3" print(f"[1] '{os.path.basename(path)}'") # [1] 'dir3' path = "/d/workspace/dir1/dir2" print(f"[2] '{os.path.basename(path)}'") # [2] 'dir2' path = "/d/workspace/dir1/dir2/" print(f"[3] '{os.p.. 2023. 1. 17.
[Python] 파이썬 파일 내 디렉토리 생성 - os.mkdir, os.makedirs 1. os.mkdir("file1") : 현재 위치의 경로에서 "file1" 생성 import os os.mkdir("file1") 2. os.makedirs("dir1/dir2/dir3/file1", exist_ok=True) - 지정한 경로 내 모든 (하위) 디렉토리 생성 - "exist_ok" : 모든 경로가 존재할 경우 에러 발생 FileExistError import os os.makedirs("dir1/dir2/dir3/file1", exist\_ok=True) 2023. 1. 17.