전체 글

이것저것
개발

[ubuntu] mpi4py 설치가 안되네..?

pytorch 컨테이너에서 pip install mpi4py을 하는데 계속 설치가 안됐다.에러메세지에 있는 것 처럼 apt install libmpich-dev libopenmpi-dev를 해도 설치가 안됐다. mpi4py 사이트에서 제공하는 가이드대로 아래와 같이 설치하니 됐다.conda install -c conda-forge mpi4py mpich

논문 및 개념 정리

[2021] ROFORMER: ENHANCED TRANSFORMER WITH ROTARYPOSITION EMBEDDING(RoPE)

RoPE를 소개한 논문의 내용을 간단히 정리하고자 한다. 1. 논문 내용RoPE 이전의 모델들은 대부분 absolute & additive한 poisition embedding을 사용했었다.RoPE는 relative & multiplicative한 방식으로 position embedding을 계산한다. 다음과 같이 $\textbf{q}_{m}, \textbf{k}_{n}, \textbf{v}_{n}$($m,n$은 position을 의미)가 있다고 하자.이때 attention은 다음과 같이 계산된다. Absolute Position Embedding의 경우 (1)을 계산할 때 다음과 같이 position 정보를 embedding에 더한다.   Rotary Position Embedding이 목표로 하는 특..

논문 및 개념 정리

[transformers] Scaled Dot Product Attention

llama구조를 참고해서 scaled dot product attention 계산 과정을 메모용으로 간단히 정리해보자. 먼저 필요한 라이브러리와 파라미터를 세팅하자.import torchfrom torch import nnimport transformersimport mathimport torch.nn.functional as Fbatch_size = 4max_seq_len = 500n_heads = 8n_kv_heads = 4embed_dim = 2048head_dim = embed_dim // num_heads # 256vocab_size = 1000 입력 토큰에 대한 임베딩을 아래와 같이 가정하자.wte = torch.nn.Embedding(vocab_size, embed_dim)token_ids..

논문 및 개념 정리

Vector Outer Product

Vector Outer Product는 Cross Product와 다르다. Vector Outer Product: In linear algebra, the outer product of two coordinate vectors is the matrix whose entries are all products of an element in the first vector with an element in the second vectorVector Cross Product: Given two linearly independent vectors a and b, the cross product, a × b (read "a cross b"), is a vector that is perpendicular to both..

개발

[ubuntu] PID로 실행중인 파일 위치 찾기

PID로 실행중인 파일 위치는 아래와 같은 방법으로 찾을 수 있다.pwdx lsof -p | grep cwd     [참고자료]https://stackoverflow.com/questions/606041/how-do-i-get-the-path-of-a-process-in-unix-linux

python 메모

[pandas] excel로 저장할 때 IllegalCharacterError가 뜰 때

pandas DataFrame을 excel로 저장할 때 IllegalCharacterError 같은 에러가 뜰 때가 있다. 이때 openpyxl로 저장하는 부분을 df.to_excel("test.xlsx", engine='openpyxl') xlsxwriter로 바꿔서 사용하면 에러가 안뜬다. df.to_excel("test.xlsx", engine='xlsxwriter')

python 메모

[sqlite] cx.read_sql, pd.read_sql 속도비교

pandas로 sqlite3 파일에서 300백만개 정도 되는 row의 데이터를 읽어올 일이 있었다. 하지만 이건 속도가 너무 느리다. connectorx와 비교해보자. 1. 사용법 비교 (1) pandas import sqlite3 import pandas as pd local_file_path = "/absolute/path/to/sqlite3/db" conn = sqlite3.connect(local_file_path) to_read = pd.read_sql( "SELECT * FROM '{tbl_name}'".format(tbl_name=tbl_name), conn, parse_dates=['timestamp'] ) (2) connectorx import connectorx as cx local_f..

개발

[websocket] (1) python websocket 서버 생성 & 클라이언트 테스트

python websockets 라이브러리를 사용해서 아주 간단한 websocket 서버를 만들어볼 수 있다. [참고문서] https://websockets.readthedocs.io/en/stable/ 1. 서버 생성 import asyncio import time import websockets import datetime import multiprocessing as mp # create handler for each connection if __name__ == "__main__": async def handler(websocket, path): while True: await websocket.send("[*] M1 from SERVER 1 "+str(datetime.datetime.now())..

개발

[ubuntu] mpi4py 설치 시 에러

ubuntu에서 pip install mpi4py로 mpi4py를 설치할 때 다음과 같이 에러메세지가 나는 경우가 있다. .... error: Cannot compile MPI programs. Check your configuration!!! [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for mpi4py Failed to build mpi4py ERROR: Could not build wheels for mpi4py, which is required to install pyproject.toml-based proje..

개발

[ChatGPT가 알려주는] overflow, underflow 파이썬 예시

Overflow and underflow are two concepts that refer to the limits of numerical representation in computing. They can happen in various programming contexts, including in Python, especially when dealing with floating-point numbers or integers that exceed the maximum or minimum size that can be represented. 1. Overflow Overflow occurs when a calculation produces a result that is larger than the max..

Fine애플
끄적끄적