Files
2024-06-05 17:13:49 +08:00

6.3 KiB

In [1]:
%env HF_ENDPOINT=https://hf-mirror.com
env: HF_ENDPOINT=https://hf-mirror.com
In [2]:
import os

# 设置 HF_HOME 环境变量 设置下载路径
os.environ['HF_HOME'] = '/data1/ckw'
In [3]:
# %pip install jieba -q
In [4]:
from transformers import AutoTokenizer
from modeling_olmo import OlmoForCausalLM

model = OlmoForCausalLM.from_pretrained("allenai/OLMo-1B-hf")
tokenizer = AutoTokenizer.from_pretrained("allenai/OLMo-1B-hf")

prompt = '\nDataWhalechina is an organization founded at Shanghai Jiao Tong University that helps learners learn artificial intelligence.'
inputs = tokenizer(prompt, return_tensors="pt")

# Generate
generate_ids = model.generate(inputs.input_ids, max_length=30)
tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
Out [4]:
model.safetensors:  16%|#5        | 744M/4.71G [00:00<?, ?B/s]
generation_config.json:   0%|          | 0.00/116 [00:00<?, ?B/s]
tokenizer_config.json:   0%|          | 0.00/493 [00:00<?, ?B/s]
tokenizer.json: 0.00B [00:00, ?B/s]
special_tokens_map.json:   0%|          | 0.00/65.0 [00:00<?, ?B/s]
'\nDataWhalechina is an organization founded at Shanghai Jiao Tong University that helps learners learn artificial intelligence.\nThe company has developed a platform'
In [5]:
generate_ids = model.generate(inputs.input_ids, max_length=300)
tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
Out [5]:
'\nDataWhalechina is an organization founded at Shanghai Jiao Tong University that helps learners learn artificial intelligence.\nThe company has developed a platform that allows users to learn AI by watching videos and answering questions.\nThe platform is designed to be easy to use and has a variety of features that make it a great choice for learners.\nDataWhalechina is a platform that helps learners learn artificial intelligence.\nThe platform is designed to be easy to use and has a variety of features that make it a great choice for learners.\nThe platform is also designed to be flexible, so that it can be used by different types of learners.\nDataWhalechina is a platform that helps learners learn artificial intelligence.\nThe platform is designed to be easy to use and has a variety of features that make it a great choice for learners.\nThe platform is also designed to be flexible, so that it can be used by different types of learners.\nDataWhalechina is a platform that helps learners learn artificial intelligence.\nThe platform is designed to be easy to use and has a variety of features that make it a great choice for learners.\nThe platform is also designed to be flexible, so that it can be used by different types of learners.\nDataWhalechina is a platform that helps learners learn artificial intelligence.\nThe platform is designed to be easy to use and has a variety of features that make it a great choice for learners.\nThe'
In [ ]:
olmo而是一款不错的模型生成速度也比较快