Views
No views yet
| Name | Quant method | Size |
|---|---|---|
| text-to-cypher.Q2_K.gguf | Q2_K | 0.04GB |
| text-to-cypher.IQ3_XS.gguf | IQ3_XS | 0.04GB |
| text-to-cypher.IQ3_S.gguf | IQ3_S | 0.04GB |
| text-to-cypher.Q3_K_S.gguf | Q3_K_S | 0.04GB |
| text-to-cypher.IQ3_M.gguf | IQ3_M | 0.04GB |
| text-to-cypher.Q3_K.gguf | Q3_K | 0.04GB |
| text-to-cypher.Q3_K_M.gguf | Q3_K_M | 0.04GB |
| text-to-cypher.Q3_K_L.gguf | Q3_K_L | 0.04GB |
| text-to-cypher.IQ4_XS.gguf | IQ4_XS | 0.04GB |
| text-to-cypher.Q4_0.gguf | Q4_0 | 0.04GB |
| text-to-cypher.IQ4_NL.gguf | IQ4_NL | 0.04GB |
| text-to-cypher.Q4_K_S.gguf | Q4_K_S | 0.04GB |
| text-to-cypher.Q4_K.gguf | Q4_K | 0.05GB |
| text-to-cypher.Q4_K_M.gguf | Q4_K_M | 0.05GB |
| text-to-cypher.Q4_1.gguf | Q4_1 | 0.05GB |
| text-to-cypher.Q5_0.gguf | Q5_0 | 0.05GB |
| text-to-cypher.Q5_K_S.gguf | Q5_K_S | 0.05GB |
| text-to-cypher.Q5_K.gguf | Q5_K | 0.05GB |
| text-to-cypher.Q5_K_M.gguf | Q5_K_M | 0.05GB |
| text-to-cypher.Q5_1.gguf | Q5_1 | 0.05GB |
| text-to-cypher.Q6_K.gguf | Q6_K | 0.06GB |
| text-to-cypher.Q8_0.gguf | Q8_0 | 0.07GB |
1pip install transformers==4.30.2
2pip install accelerate==0.20.3
3pip install torch==2.0.11from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4def generate_response(prompt, model_name):
5 tokenizer = AutoTokenizer.from_pretrained(
6 model_name,
7 use_fast=True,
8 trust_remote_code=True,
9 )
10
11 model = AutoModelForCausalLM.from_pretrained(
12 model_name,
13 torch_dtype=torch.float32,
14 device_map={"": "cpu"},
15 trust_remote_code=True,
16 )
17 model.cpu().eval()
18
19 inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to("cpu")
20
21 tokens = model.generate(
22 input_ids=inputs["input_ids"],
23 attention_mask=inputs["attention_mask"],
24 min_new_tokens=2,
25 max_new_tokens=500,
26 do_sample=False,
27 num_beams=2,
28 temperature=float(0.0),
29 repetition_penalty=float(1.0),
30 renormalize_logits=True
31 )[0]
32
33 tokens = tokens[inputs["input_ids"].shape[1]:]
34 answer = tokenizer.decode(tokens, skip_special_tokens=True)
35
36 return answer1model_name = "diegomiranda/text-to-cypher"
2prompt = "Create a Cypher statement to answer the following question:Retorne os processos de Direito Tributário que se baseiam em lei 939 de 1992?<|endoftext|>"
3response = generate_response(prompt, model_name)
4print(response)transformers library on a machine with GPUs, first make sure you have the transformers library installed.pip install transformers==4.31.0token=True in the pipeline and login to hugginface_hub by running
python import huggingface_hub huggingface_hub.login(<ACCES_TOKEN>)
- Or directly pass your <ACCES_TOKEN> to token in the pipeline1from transformers import pipeline
2
3generate_text = pipeline(
4 model="diegomiranda/text-to-cypher",
5 torch_dtype="auto",
6 trust_remote_code=True,
7 use_fast=True,
8 device_map={"": "cuda:0"},
9 token=True,
10)
11
12res = generate_text(
13 "Why is drinking water so healthy?",
14 min_new_tokens=2,
15 max_new_tokens=500,
16 do_sample=False,
17 num_beams=2,
18 temperature=float(0.0),
19 repetition_penalty=float(1.0),
20 renormalize_logits=True
21)
22print(res[0]["generated_text"])print(generate_text.preprocess("Why is drinking water so healthy?")["prompt_text"])Why is drinking water so healthy?<|endoftext|>transformers package, this will allow you to set trust_remote_code=False.1from h2oai_pipeline import H2OTextGenerationPipeline
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4tokenizer = AutoTokenizer.from_pretrained(
5 "diegomiranda/text-to-cypher",
6 use_fast=True,
7 padding_side="left",
8 trust_remote_code=True,
9)
10model = AutoModelForCausalLM.from_pretrained(
11 "diegomiranda/text-to-cypher",
12 torch_dtype="auto",
13 device_map={"": "cuda:0"},
14 trust_remote_code=True,
15)
16generate_text = H2OTextGenerationPipeline(model=model, tokenizer=tokenizer)
17
18res = generate_text(
19 "Why is drinking water so healthy?",
20 min_new_tokens=2,
21 max_new_tokens=500,
22 do_sample=False,
23 num_beams=2,
24 temperature=float(0.0),
25 repetition_penalty=float(1.0),
26 renormalize_logits=True
27)
28print(res[0]["generated_text"])1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "diegomiranda/text-to-cypher" # either local folder or huggingface model name
4# Important: The prompt needs to be in the same format the model was trained with.
5# You can find an example prompt in the experiment logs.
6prompt = "How are you?<|endoftext|>"
7
8tokenizer = AutoTokenizer.from_pretrained(
9 model_name,
10 use_fast=True,
11 trust_remote_code=True,
12)
13model = AutoModelForCausalLM.from_pretrained(
14 model_name,
15 torch_dtype="auto",
16 device_map={"": "cuda:0"},
17 trust_remote_code=True,
18)
19model.cuda().eval()
20inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to("cuda")
21
22# generate configuration can be modified to your needs
23tokens = model.generate(
24 input_ids=inputs["input_ids"],
25 attention_mask=inputs["attention_mask"],
26 min_new_tokens=2,
27 max_new_tokens=500,
28 do_sample=False,
29 num_beams=2,
30 temperature=float(0.0),
31 repetition_penalty=float(1.0),
32 renormalize_logits=True
33)[0]
34
35tokens = tokens[inputs["input_ids"].shape[1]:]
36answer = tokenizer.decode(tokens, skip_special_tokens=True)
37print(answer)load_in_8bit=True or load_in_4bit=True. Also, sharding on multiple GPUs is possible by setting device_map=auto.GPTNeoXForCausalLM(
(gpt_neox): GPTNeoXModel(
(embed_in): Embedding(50304, 512)
(emb_dropout): Dropout(p=0.0, inplace=False)
(layers): ModuleList(
(0-5): 6 x GPTNeoXLayer(
(input_layernorm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)
(post_attention_layernorm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)
(post_attention_dropout): Dropout(p=0.0, inplace=False)
(post_mlp_dropout): Dropout(p=0.0, inplace=False)
(attention): GPTNeoXAttention(
(rotary_emb): GPTNeoXRotaryEmbedding()
(query_key_value): Linear(in_features=512, out_features=1536, bias=True)
(dense): Linear(in_features=512, out_features=512, bias=True)
(attention_dropout): Dropout(p=0.0, inplace=False)
)
(mlp): GPTNeoXMLP(
(dense_h_to_4h): Linear(in_features=512, out_features=2048, bias=True)
(dense_4h_to_h): Linear(in_features=2048, out_features=512, bias=True)
(act): GELUActivation()
)
)
)
(final_layer_norm): LayerNorm((512,), eps=1e-05, elementwise_affine=True)
)
(embed_out): Linear(in_features=512, out_features=50304, bias=False)
)