Views
No views yet
ollama pull hf.co/aokitools/japanese-laws-egov-base-2025080114341ollama list
2ollama rm hf.co/aokitools/japanese-laws-egov-base-202508011434:latest
3ollama list1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
4model_name = "aokitools/japanese-laws-egov-base-202508011434"
5
6quant_config = BitsAndBytesConfig(
7 load_in_8bit=True,
8 llm_int8_threshold=6.0,
9)
10
11# load the tokenizer and the model
12tokenizer = AutoTokenizer.from_pretrained(model_name)
13model = AutoModelForCausalLM.from_pretrained(
14 model_name,
15 torch_dtype=torch.float16,
16 device_map="auto",
17 quantization_config=quant_config,
18)
19
20# prepare the model input
21prompt = "Give me a short introduction to large language model."
22messages = [
23 {"role": "user", "content": prompt}
24]
25text = tokenizer.apply_chat_template(
26 messages,
27 tokenize=False,
28 add_generation_prompt=True,
29 enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
30)
31model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
32
33# conduct text completion
34generated_ids = model.generate(
35 **model_inputs,
36 max_new_tokens=256
37)
38output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
39
40# parsing thinking content
41try:
42 # rindex finding 151668 (</think>)
43 index = len(output_ids) - output_ids[::-1].index(151668)
44except ValueError:
45 index = 0
46
47thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
48content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
49
50print("thinking content:", thinking_content)
51print("content:", content)