Views
No views yet
HfApi.upload_folder() given problems when pushing
the LoRA adapters to HF in any other of the formats tested so far.local_dir parameter rather than using HF's local cache, to download the checkpoint to a local directory
(~/models/llama-carvalho-scansion-gl-sg in the example):1from pathlib import Path
2from huggingface_hub import snapshot_download
3
4snapshot_download(
5 repo_id="compellit/llama-carvalho-scansion-gl-sg",
6 local_dir=Path("~/models/llama-carvalho-scansion-gl-sg").expanduser(),
7)"E / os / *her- / mos / re- / ver- / *de- / cen / do / es- / *pri- / to / on- / de / mo- / *ra- / ren"E os / *her- / mos / re- / ver- / *de- / cen / do es- / *pri- / to on- / de / mo- / *ra- / ren1from pathlib import Path
2
3import torch
4import unsloth
5from unsloth import FastLanguageModel
6
7model_name = str(Path("~/models/llama-carvalho-scansion-gl-sg").expanduser().resolve())
8
9max_seq_length = 512
10load_in_4bit = True
11
12model, tokenizer = FastLanguageModel.from_pretrained(
13 model_name=model_name,
14 max_seq_length=max_seq_length,
15 dtype=None,
16 load_in_4bit=load_in_4bit,
17)
18FastLanguageModel.for_inference(model)
19
20
21instruction = """
22I need to scan some lines (scansion is the syllabic division of poetic lines and identification of stresses).
23
24I will give you the lexical syllabification of each line as input. Based on this, you need to identify metrical syllables. This will require merging some syllables (erasing syllable boundaries) and splitting others (adding syllable boundaries).
25
26The input format is:
271. Syllables separated by " / ".
282. Each lexically stressed syllable is preceded by "*".
29
30The desired output format is:
311. Syllables separated by " / ".
322. Each metrically stressed syllable is preceded by "*".
33
34Do not carry out any other modifications to the input, just modify syllable boundaries if needed.
35
36Do not repeat the scanned line more than once, use as few output tokens as possible but as many as needed.
37
38"""
39
40example = "E / os / *her- / mos / re- / ver- / *de- / cen / do / es- / *pri- / to / on- / de / mo- / *ra- / ren"
41
42messages = [
43 {"role": "system", "content": instruction.strip()},
44 {"role": "user", "content": example},
45]
46prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
47
48inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
49
50with torch.inference_mode():
51 outputs = model.generate(
52 inputs["input_ids"],
53 max_new_tokens=64,
54 pad_token_id=tokenizer.pad_token_id,
55 eos_token_id=tokenizer.eos_token_id,
56 do_sample=False,
57 )
58
59prompt_len = inputs["input_ids"].shape[1]
60generated_tokens = outputs[0][prompt_len:]
61print(tokenizer.decode(generated_tokens, skip_special_tokens=True).strip())