Spaces:
Sleeping
Sleeping
Download utils/model_utils.py from Keyvan1986/Emma: direct link, hf CLI and curl.
- Browser
- Download file 669 Bytes
-
https://huggingface.co/spaces/Keyvan1986/Emma/resolve/main/utils/model_utils.py
- Command line
-
hf download hf://spaces/Keyvan1986/Emma/utils/model_utils.py
-
curl -L -o model_utils.py https://huggingface.co/spaces/Keyvan1986/Emma/resolve/main/utils/model_utils.py
669 Bytes
| from transformers.generation.logits_process import LogitsProcessor | |
| from transformers import ( | |
| AutoConfig, | |
| AutoModel, | |
| AutoTokenizer, | |
| AutoTokenizer, | |
| set_seed, | |
| ) | |
| from transformers import GenerationConfig, LlamaForCausalLM, LlamaTokenizer | |
| from peft import PeftModel | |
| import torch, os | |
| max_chunk_overlap = 20 | |
| pre_seq_len = 128 | |
| prefix_projection = False | |
| 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[..., 5] = 5e4 | |
| return scores |