Run this model with HF Jobs
Run zai-org/chatglm-6b on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/zai-org/chatglm-6b. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/zai-org/chatglm-6b on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use zai-org/chatglm-6b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/chatglm-6b with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("zai-org/chatglm-6b", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
duzx16 commited on
Commit ·
c3dece3
1
Parent(s): 9d1509a
Add logit processor for NaN or Inf scores
Browse files2 unmodified lines34567814 unmodified lines232425262728293013 unmodified lines4445464748491028 unmodified lines107810791080108110821083108410851086108710882 unmodified linesimport mathimport copyimport osimport torchimport torch.utils.checkpoint14 unmodified linesBaseModelOutputWithPastAndCrossAttentions,)from transformers.modeling_utils import PreTrainedModelfrom transformers.utils import loggingfrom .configuration_chatglm import ChatGLMConfig# flags required to enable jit fusion kernels13 unmodified lines]def load_tf_weights_in_chatglm_6b(model, config, tf_checkpoint_path):"""Load tf checkpoints in a pytorch model."""try:1028 unmodified lines@torch.no_grad()def chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 2048, num_beams=1,do_sample=True, top_p=0.7, temperature=0.95, **kwargs):if history is None:history = []gen_kwargs = {"max_length": max_length, "num_beams": num_beams, "do_sample": do_sample, "top_p": top_p,"temperature": temperature, **kwargs}if not history:prompt = queryelse:2 unmodified lines345678914 unmodified lines2425262728293031323313 unmodified lines47484950515253545556575859601028 unmodified lines108910901091109210931094109510961097109810991100110111022 unmodified linesimport mathimport copyimport osimport timeimport torchimport torch.utils.checkpoint14 unmodified linesBaseModelOutputWithPastAndCrossAttentions,)from transformers.modeling_utils import PreTrainedModelfrom transformers.utils import loggingfrom transformers.generation.logits_process import LogitsProcessorfrom transformers.generation.utils import LogitsProcessorListfrom .configuration_chatglm import ChatGLMConfig# flags required to enable jit fusion kernels13 unmodified lines]class InvalidScoreLogitsProcessor(LogitsProcessor):def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:if torch.isnan(scores).any() or torch.isinf(scores).any():scores.zero_()scores[..., 20005] = 1e5return scoresdef load_tf_weights_in_chatglm_6b(model, config, tf_checkpoint_path):"""Load tf checkpoints in a pytorch model."""try:1028 unmodified lines@torch.no_grad()def chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 2048, num_beams=1,do_sample=True, top_p=0.7, temperature=0.95, logits_processor=None, **kwargs):if history is None:history = []if logits_processor is None:logits_processor = LogitsProcessorList()logits_processor.append(InvalidScoreLogitsProcessor())gen_kwargs = {"max_length": max_length, "num_beams": num_beams, "do_sample": do_sample, "top_p": top_p,"temperature": temperature, "logits_processor": logits_processor, **kwargs}if not history:prompt = queryelse:
modeling_chatglm.py+17-3