iShare commited on
Commit
80df905
1 Parent(s): 6f3249f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -24
app.py CHANGED
@@ -1,25 +1,32 @@
1
- #Python版本的transformers pipeline API
2
- #https://huggingface.co/docs/transformers/main_classes/pipelines
3
-
4
- #Java版本的transformers pipeline API
5
- #https://huggingface.co/docs/transformers.js/pipelines#available-tasks
6
-
7
- #Python版本示例:https://huggingface.co/docs/transformers/main_classes/pipelines
8
- from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
9
-
10
- # Sentiment analysis pipeline
11
- analyzer = pipeline("sentiment-analysis")
12
- #sentiment-analysis的default model是distilbert-base-uncased-finetuned-sst-2-english
13
- #https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english?text=I+like+you.+I+love+you
14
- #https://huggingface.co/blog/sentiment-analysis-python
15
-
16
- # Question answering pipeline, specifying the checkpoint identifier
17
- oracle = pipeline(
18
- "question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="bert-base-cased"
19
- )
20
-
21
- # Named entity recognition pipeline, passing in a specific model and tokenizer
22
- model = AutoModelForTokenClassification.from_pretrained("dbmdz/bert-large-cased-finetuned-conll03-english")
23
- tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
24
- recognizer = pipeline("ner", model=model, tokenizer=tokenizer)
 
 
 
 
 
 
 
25
 
 
1
+ #https://huggingface.co/TheBloke/starchat-beta-GPTQ
2
+
3
+ from transformers import AutoTokenizer, pipeline, logging
4
+ from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
5
+ import argparse
6
+
7
+ model_name_or_path = "TheBloke/starchat-beta-GPTQ"
8
+ # Or to load it locally, pass the local download path
9
+ # model_name_or_path = "/path/to/models/The_Bloke_starchat-beta-GPTQ"
10
+
11
+ use_triton = False
12
+
13
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
14
+
15
+ model = AutoGPTQForCausalLM.from_quantized(model_name_or_path,
16
+ use_safetensors=True,
17
+ #device="cuda:0",
18
+ use_triton=use_triton,
19
+ quantize_config=None)
20
+
21
+ # Prevent printing spurious transformers error when using pipeline with AutoGPTQ
22
+ logging.set_verbosity(logging.CRITICAL)
23
+
24
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
25
+
26
+ prompt_template = "<|system|>\n<|end|>\n<|user|>\n{query}<|end|>\n<|assistant|>"
27
+ prompt = prompt_template.format(query="How do I sort a list in Python?")
28
+ # We use a special <|end|> token with ID 49155 to denote ends of a turn
29
+ outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.2, top_k=50, top_p=0.95, eos_token_id=49155)
30
+ # You can sort a list in Python by using the sort() method. Here's an example:\n\n```\nnumbers = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]\nnumbers.sort()\nprint(numbers)\n```\n\nThis will sort the list in place and print the sorted list.
31
+ print(outputs[0]['generated_text'])
32