ilu000 commited on
Commit
25082f9
1 Parent(s): 1bb5c8a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +44 -10
README.md CHANGED
@@ -33,13 +33,10 @@ pip install torch==2.0.0
33
  pip install einops==0.6.1
34
  ```
35
 
36
- Download [h2oai_pipeline.py](h2oai_pipeline.py), store it alongside your notebook, and construct the pipeline yourself from the loaded model and tokenizer:
37
-
38
-
39
  ```python
40
  import torch
41
- from h2oai_pipeline import H2OTextGenerationPipeline
42
- from transformers import AutoModelForCausalLM, AutoTokenizer
43
 
44
  tokenizer = AutoTokenizer.from_pretrained(
45
  "h2oai/h2ogpt-gm-oasst1-multilang-2048-falcon-7b",
@@ -47,13 +44,15 @@ tokenizer = AutoTokenizer.from_pretrained(
47
  padding_side="left",
48
  trust_remote_code=True,
49
  )
50
- model = AutoModelForCausalLM.from_pretrained(
51
- "h2oai/h2ogpt-gm-oasst1-multilang-2048-falcon-7b",
52
- torch_dtype=torch.bfloat16,
53
- device_map={"": "cuda:0"},
 
54
  trust_remote_code=True,
 
 
55
  )
56
- generate_text = H2OTextGenerationPipeline(model=model, tokenizer=tokenizer)
57
 
58
  res = generate_text(
59
  "Why is drinking water so healthy?",
@@ -78,6 +77,41 @@ print(generate_text.preprocess("Why is drinking water so healthy?")["prompt_text
78
  <|prompt|>Why is drinking water so healthy?<|endoftext|><|answer|>
79
  ```
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  You may also construct the pipeline from the loaded model and tokenizer yourself and consider the preprocessing steps:
82
 
83
  ```python
 
33
  pip install einops==0.6.1
34
  ```
35
 
 
 
 
36
  ```python
37
  import torch
38
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
39
+
40
 
41
  tokenizer = AutoTokenizer.from_pretrained(
42
  "h2oai/h2ogpt-gm-oasst1-multilang-2048-falcon-7b",
 
44
  padding_side="left",
45
  trust_remote_code=True,
46
  )
47
+
48
+ generate_text = pipeline(
49
+ model="h2oai/h2ogpt-gm-oasst1-multilang-2048-falcon-7b",
50
+ tokenizer=tokenizer,
51
+ torch_dtype=torch.float16,
52
  trust_remote_code=True,
53
+ use_fast=False,
54
+ device_map={"": "cuda:0"},
55
  )
 
56
 
57
  res = generate_text(
58
  "Why is drinking water so healthy?",
 
77
  <|prompt|>Why is drinking water so healthy?<|endoftext|><|answer|>
78
  ```
79
 
80
+ Alternatively, you can download [h2oai_pipeline.py](h2oai_pipeline.py), store it alongside your notebook, and construct the pipeline yourself from the loaded model and tokenizer:
81
+
82
+
83
+ ```python
84
+ import torch
85
+ from h2oai_pipeline import H2OTextGenerationPipeline
86
+ from transformers import AutoModelForCausalLM, AutoTokenizer
87
+
88
+ tokenizer = AutoTokenizer.from_pretrained(
89
+ "h2oai/h2ogpt-gm-oasst1-multilang-2048-falcon-7b",
90
+ use_fast=False,
91
+ padding_side="left",
92
+ trust_remote_code=True,
93
+ )
94
+ model = AutoModelForCausalLM.from_pretrained(
95
+ "h2oai/h2ogpt-gm-oasst1-multilang-2048-falcon-7b",
96
+ torch_dtype=torch.bfloat16,
97
+ device_map={"": "cuda:0"},
98
+ trust_remote_code=True,
99
+ )
100
+ generate_text = H2OTextGenerationPipeline(model=model, tokenizer=tokenizer)
101
+
102
+ res = generate_text(
103
+ "Why is drinking water so healthy?",
104
+ min_new_tokens=2,
105
+ max_new_tokens=1024,
106
+ do_sample=False,
107
+ num_beams=1,
108
+ temperature=float(0.3),
109
+ repetition_penalty=float(1.2),
110
+ renormalize_logits=True
111
+ )
112
+ print(res[0]["generated_text"])
113
+ ```
114
+
115
  You may also construct the pipeline from the loaded model and tokenizer yourself and consider the preprocessing steps:
116
 
117
  ```python