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

Update code, Support CPU #25

Merged
merged 9 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 3 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
print('Done'.center(64, '-'))

# 加载模型
# model_name = 'THUDM/chatglm-6b'
model_name = 'silver/chatglm-6b-int4-slim'
# model_name = 'BelleGroup/BELLE-LLAMA-7B-2M'
# model_name = 'BelleGroup/BELLE-LLAMA-7B-2M-gptq'
model_name = 'THUDM/chatglm-6b'
# model_name = 'silver/chatglm-6b-int4-slim'

if 'chatglm' in model_name.lower():
from predictors.chatglm_predictor import ChatGLM
Expand Down Expand Up @@ -97,3 +95,4 @@ def interrupt(allow_generate):
outputs=[chatbot, query, continue_message])
interrupt_btn.click(interrupt, inputs=[allow_generate])
demo.queue(concurrency_count=4).launch(server_name='0.0.0.0', server_port=7860, share=False, inbrowser=False)
demo.close()
24 changes: 19 additions & 5 deletions chatglm/configuration_chatglm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class ChatGLMConfig(PretrainedConfig):
It is used to instantiate an ChatGLM model according to the specified arguments, defining the model
architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of
the ChatGLM-6B [THUDM/ChatGLM-6B](https://huggingface.co/THUDM/chatglm-6b) architecture.

Configuration objects inherit from [`PretrainedConfig`] and can be used
to control the model outputs. Read the documentation from [`PretrainedConfig`]
for more information.


Args:
vocab_size (`int`, *optional*, defaults to 150528):
Vocabulary size of the ChatGLM-6B model. Defines the number of different tokens that can be represented by the
Expand All @@ -36,13 +39,17 @@ class ChatGLMConfig(PretrainedConfig):
use_cache (`bool`, *optional*, defaults to `True`):
Whether the model should return the last key/values attentions (not used by all models).
Example:

```python
>>> from chatglm.configuration_chatglm import ChatGLMConfig
>>> from chatglm.modeling_chatglm import ChatGLMModel
>>> from configuration_chatglm import ChatGLMConfig
>>> from modeling_chatglm import ChatGLMModel

>>> # Initializing a ChatGLM-6B THUDM/ChatGLM-6B style configuration
>>> configuration = ChatGLMConfig()

>>> # Initializing a model from the THUDM/ChatGLM-6B style configuration
>>> model = ChatGLMModel(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```
Expand All @@ -59,12 +66,15 @@ def __init__(
use_cache=False,
bos_token_id=150004,
eos_token_id=150005,
mask_token_id=150000,
gmask_token_id=150001,
pad_token_id=0,
max_sequence_length=2048,
inner_hidden_size=16384,
position_encoding_2d=True,
quantization_bit=0,
quantization_embeddings=False,
pre_seq_len=None,
prefix_projection=False,
**kwargs
):
self.num_layers = num_layers
Expand All @@ -78,9 +88,13 @@ def __init__(
self.bos_token_id = bos_token_id
self.eos_token_id = eos_token_id
self.pad_token_id = pad_token_id
self.mask_token_id = mask_token_id
self.gmask_token_id = gmask_token_id
self.position_encoding_2d = position_encoding_2d
self.quantization_bit=quantization_bit
self.quantization_embeddings=quantization_embeddings
self.quantization_bit = quantization_bit
self.pre_seq_len = pre_seq_len
self.prefix_projection = prefix_projection

super().__init__(
pad_token_id=pad_token_id,
bos_token_id=bos_token_id,
Expand Down
Loading