Views
No views yet
1lora_alpha = 16
2lora_dropout = 0.1
3lora_r = 81#確認安裝所需套件
2!pip install -q -U trl transformers accelerate git+https://github.com/huggingface/peft.git
3
4#LlamaTokenizer requires the SentencePiece library
5!pip install sentencepiece1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
4model_name = "stuser2023/Llama3-8b-finetuned"
5
6quantization_config = BitsAndBytesConfig(load_in_4bit=True) #約使用GPU記憶體14.2Gb
7
8model = AutoModelForCausalLM.from_pretrained(
9 model_name,
10 quantization_config=quantization_config,
11 device_map={'': 0}, # 設定使用的設備,此處指定為 GPU 0
12 trust_remote_code=True,
13)
14
15model.config.use_cache = False
16model=model.eval() #把Dropout功能關掉1tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, padding=True)
2tokenizer.pad_token = tokenizer.eos_token
3
4role = "user" #The possible roles can be: system, user, assistant.
5text = "在未來的2040年,人類社會將進入"
6
7input_template = f"""<|begin_of_text|><|start_header_id|>{role}<|end_header_id|>{text}<|eot_id|>"""
8input_ids = tokenizer([input_template], return_tensors="pt",add_special_tokens=False).input_ids.to('cuda')
9
10generate_input = {
11 "input_ids":input_ids,
12 "max_new_tokens":384,
13 "do_sample":True,
14 "top_k":50,
15 "top_p":0.95,
16 "temperature":0.3,
17 "repetition_penalty":1.3,
18 "eos_token_id":tokenizer.eos_token_id,
19 "bos_token_id":tokenizer.bos_token_id,
20 "pad_token_id":tokenizer.pad_token_id
21}
22generate_ids = model.generate(**generate_input)
23text = tokenizer.decode(generate_ids[0])
24print(text)1'''
2user在未來的2040年,人類社會將進入assistant
3
4You want to know what human society will be like in 20 years? Well, I can give you some predictions based on current trends and technological advancements. Here are a few things that might happen:
5
61. Humans could have colonized other planets: With the help of advanced technology such as space travel vehicles and habitats for humans outside Earth's atmosphere, it is possible that humanity has already begun exploring new worlds by then.
7
82. Artificial intelligence (AI) would become more prevalent: AI systems continue to improve their ability to perform tasks previously done only by people. In this future world, many jobs may no longer require manual labor or decision-making skills because they'll all be handled automatically through automation.
9
103. Virtual reality becomes indistinguishable from real life: Advances in virtual reality technologies allow us to experience fully immersive environments with lifelike graphics and sounds so realistic we forget about our physical surroundings!
11
124. Human lifespan increases significantly due to medical breakthroughs: Thanks to ongoing research into aging-related diseases and treatments, there’s hope that most people will live well over 100 years without any major health issues!assistant
13
14I think these changes won't come true until much later than 2039. The first one seems unlikely since establishing colonies elsewhere requires significant resources which aren’t available yet; even if those were accessible now, setting up an entire colony takes time too.
15The second prediction also doesn’t seem very likely given how quickly artificial intelligence improves but still hasn’t replaced every job requiring human skillset entirely – at least not currently!
16As far as VR goes, while progress continues being made towards creating better experiences within them, full immersion isn’t quite here just yet either. People need something else besides visuals alone before forgetting where they’re physically located.
17Lastly regarding longevity increase thanks to medicine advances, though scientists work hard toward finding cures against age related illnesses & improving overall healthcare outcomes, reaching
18'''