This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from transformers import AutoModelForCausalLM, AutoTokenizer | |
input_path = "./model_in" | |
output_path = "./model_out" | |
max_shard_size = "5GB" | |
new_max_length = 4096 | |
print("load model...start") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_code(inputs: dict) -> dict: | |
text = inputs["text"] | |
result = re.search(r'```.*?\n(.*?)\n```', text, re.DOTALL) | |
result = result.group(1) if result else text | |
return {"output": result} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd) | |
cd $SCRIPT_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
# Copyright 2023 The HuggingFace Inc. team. All rights reserved. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tested this works https://stackoverflow.com/a/57014278/6147756 | |
Single command: | |
MAKEFLAGS="-j$(nproc)" pip install xxx | |
Enable for all commands in a script: | |
export MAKEFLAGS="-j$(nproc)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_available_ports(port_from=5000, port_to=6000): | |
import socket | |
for port in range(port_from, port_to): | |
try: | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind(('localhost', port)) | |
s.close() | |
yield port | |
except: | |
continue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def strip_codeblock(code_with_codeblock): | |
first_newline_idx = code_with_codeblock.find("\n") | |
code_tmp = code_with_codeblock[first_newline_idx+1:] | |
code_closing_idx = code_tmp.find("```") | |
code_striped = code_tmp[:code_closing_idx] | |
return code_striped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -N -X 'POST' \ [12:04:09] | |
'http://localhost:8080/v1/chat-streaming' \ | |
-H 'Content-Type: application/json' \ | |
-H 'Accept: text/event-stream' \ | |
-d '{ | |
"turns": [ | |
{ | |
"role": "user", | |
"content": "fastapi 사용법" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DataType(str, Enum): | |
WITH_SUFFIX = "WITH_SUFFIX" | |
WITHOUT_SUFFIX = "WITHOUT_SUFFIX" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def reservoir_sampling(file_name, k): | |
sample = [] | |
with open(file_name, 'r') as f: | |
f.seek(0, 2) # 파일의 끝으로 이동 | |
filesize = f.tell() # 파일의 크기를 얻음 (바이트) | |
random_set = sorted(random.sample(range(filesize), k)) |
NewerOlder