Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持 BelleGroup/BELLE-LLAMA-7B-2M-gptq #12

Merged
merged 8 commits into from
Apr 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update llama.py
ypw committed Apr 1, 2023
commit 268d2e31d227f3cc9bc59970bf4e06a7bf637df7
19 changes: 13 additions & 6 deletions predictors/llama.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from transformers import LlamaForCausalLM, AutoTokenizer
import torch
import torch.nn as nn
from typing import List, Tuple, Optional, Callable
from predictors.base import BasePredictor
import copy
import time
import warnings
from transformers.utils import logging
from typing import List, Tuple, Optional, Callable

import torch
import torch.nn as nn
from transformers import LlamaForCausalLM, AutoTokenizer
from transformers.generation.utils import LogitsProcessorList, StoppingCriteriaList, GenerationConfig
from transformers.utils import logging

from predictors.base import BasePredictor

logger = logging.get_logger(__name__)

@@ -117,6 +120,8 @@ def stream_generate(
class LLaMa(BasePredictor):

def __init__(self, model_name):
print(f'Loading model {model_name}')
start = time.perf_counter()
self.model_name = model_name
self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
self.tokenizer = AutoTokenizer.from_pretrained(
@@ -128,6 +133,8 @@ def __init__(self, model_name):
torch_dtype=torch.float16 if self.device == 'cuda' else torch.float32,
device_map={'': self.device})
self.model.eval()
end = time.perf_counter()
print(f'Successfully loaded model {model_name}, time cost: {end - start:.2f}s')

@torch.no_grad()
def stream_chat_continue(self,