전체 글

이것저것
개발

[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..

개발

[ubuntu] nohup 파일 생성 시 현재 날짜로 생기게 하기

nohup echo "hi" &> nohup$(date --iso).out & 이와 같이 $(date --iso)를 사용하면 현재 날짜를 기준으로 한 로그를 남길 수 있다.

python 메모

[matplotlib] 여러개의 다른 y축 그래프를 한 그래프에 그리기

같은 x축에 대해 서로 다른 y scale의 그래프를 그릴 일이 있다. 아래와 같이 그리면 된다. import matplotlib.pyplot as plt fig, ax = plt.subplots() fig.subplots_adjust(right=0.75) twin1 = ax.twinx() twin2 = ax.twinx() twin3 = ax.twinx() # Offset the right spine of twin2. The ticks and label have already been # placed on the right by twinx above. twin2.spines.right.set_position(("axes", 1.2)) twin3.spines.right.set_position(("axes"..

개발

[ubuntu] crontab 사용법 간단정리

1. Cron Job 등록 crontab -e로 job을 등록할 수 있다. # crontab -e 실행 후 아래 line 등록 # 매월 9일 21시 8분에 run.sh 실행 8 21 9 * * /home/user/.../run.sh # weekday(월-금) 매일 18시 0분에 run.sh 실행 0 18 * * 1-5 /home/user/.../run.sh 2. Cron Job 확인 crontab -l을 확인하면 등록한 job 목록을 보여준다. user@user-System-Product-Name:~/$ crontab -l MAILTO="" # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be define..

개발

[ubuntu] 좀비 프로세스 죽이기(defunct)

ps -ef | grep defunct로 좀비 프로세스를 확인해보면 다음과 같이 나온다. 이때 34502가 parant process id인데 얘를 죽여주면 하위 프로세스들도 죽는다. sudo kill -9 34502 ps -ef | grep defunct user 32872 30725 0 14:49 pts/0 00:00:00 grep --color=auto defunct

python 메모

[python] list를 chunk로 나누는 방법들(메모)

ChatGPT가 알려준 리스트를 나누는 방법들을 정리해두고자 한다. 1. 리스트를 특정 크기로 자르기 def split_list_into_chunks(lst, chunk_size): """ Split a list into chunks of the specified size. Parameters: - lst: The list to be split. - chunk_size: The size of each chunk. Returns: A list of chunks, where each chunk is a sublist of the original list. """ return [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)] my_list = [..

python 메모

[regex] 정규표현식 메모용

일하면서 사용했던 정규표현식을 정리해두고자 한다. 1. HTML에서 주석() 부분 찾기 HTML에서 주석 부분만 찾는 표현식이다. 정규표현식: python으로는 아래와 같이 사용할 수 있다. text = """ 이것은 주석이 아닙니다 """ import re text = re.sub(r'','', text) text >>>> '\n이것은 주석이 아닙니다\n\n' 2. HTML에서 공백인 부분 제거 BeautifulSoup을 사용해서 표를 파싱한 후 soup.prettify(formatter="html")를 하면 불필요한 공백이 많이 생성된다. 이때 2개 이상 이어진 공백에서 하나만 남기고 나머지 공백들을 제거하는 표현식이다. 정규표현식: \B\s+|\s+\B^ python으로는 아래와 같이 사용할 수 있..

python 메모

[websocket] 연결이 끊겼을 때 reconnect를 위한 방법들

파이썬에는 웹소켓 사용을 위한 websocket, websockets(두개가 다른 거다) 라이브러리가 있다. 웹소켓 연결이 끊겼을 때를 대비하기 위한 방법이 각각 다른데 이를 간단히 정리해두고자 한다. 1. websocket websocket 라이브러리는 pip install websocket-client로 설치할 수 있다. 공식 github에 가서 보면 아래와 같은 설명이 있다(링크). The WebSocketApp run_forever loop will automatically try to reconnect to an open WebSocket connection when a network connection... run_forever does not automatically reconnect if ..

python 메모

[GPU] pynvml 모듈로 gpu 사용량 체크하기

GPU 모니터링 툴이 별도로 없을 때 pynvml을 사용하여 GPU 사용량 정보 등을 로그로 남길 수 있는 방법을 정리하고자 한다. 1. GPU 정보 확인하기 import pynvml print("Driver Version:", pynvml.nvmlSystemGetDriverVersion()) >>>> Driver Version: 4xx.1xx.xx 2. GPU 사용량 체크하기 GPU가 여러 장 있을 때 GPU별 utilization, memory 사용량 평균을 다음과 같이 기록해둘 수 있다. from threading import Thread import numpy as np import torch .... if __name__ == "__main__": def schedule_gpu_memory_lo..

논문 및 개념 정리

[2023] The Wisdom of Hindsight Makes Language Models Better Instruction Followers

0. Abstract We consider an alternative approach: converting feedback to instruction by relabeling the original one and training the model for better alignment in a supervised manner 1. Introduction Human alignment를 위해 두 가지 정도의 방향성이 있음 Proximal Policy Optimization (PPO): rather complex, sensitive to hyperparameters, and requires additional training in the reward model and value network imitation ..