Views
No views yet

git lfs install
git clone https://huggingface.co/zjunlp/OceanGPT-basic-30B-A3B-Instructhuggingface-cli download --resume-download zjunlp/OceanGPT-basic-30B-A3B-Instruct --local-dir OceanGPT-basic-30B-A3B-Instruct --local-dir-use-symlinks False1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_name = "zjunlp/OceanGPT-basic-30B-A3B-Instruct"
4
5# load the tokenizer and the model
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 torch_dtype="auto",
10 device_map="auto"
11)
12
13# prepare the model input
14system_prompt = "你是海洋知识专家,负责解答各类海洋相关问题(You are a marine knowledge expert, responsible for answering all marine-related questions)."
15question = "<Your Question>"
16messages = [
17 {"role": "system", "content": system_prompt},
18 {"role": "user", "content": question}
19]
20text = tokenizer.apply_chat_template(
21 messages,
22 tokenize=False,
23 add_generation_prompt=True,
24)
25model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
26
27# conduct text completion
28generated_ids = model.generate(
29 **model_inputs,
30 max_new_tokens=4096
31)
32output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
33
34content = tokenizer.decode(output_ids, skip_special_tokens=True)
35
36print("content:", content)
371@article{bi2023oceangpt,
2 title={OceanGPT: A Large Language Model for Ocean Science Tasks},
3 author={Bi, Zhen and Zhang, Ningyu and Xue, Yida and Ou, Yixin and Ji, Daxiong and Zheng, Guozhou and Chen, Huajun},
4 journal={arXiv preprint arXiv:2310.02031},
5 year={2023}
6}