Views
No views yet
A as random projections and sparsifying the matrices B using task-specific masks. This design substantially reduces the number of trainable parameters while maintaining strong task performance, minimizing cross-task interference in adapter merging, and supporting continual learning by mitigating catastrophic forgetting.
meta-llama/Meta-Llama-3-8B base model with an adapter rank of 64. The LoRI approach has been demonstrated to outperform full fine-tuning and existing PEFT methods, using up to 95% fewer trainable parameters than standard LoRA. This model is part of a broader set of LoRI adapters that cover natural language understanding, mathematical reasoning, code generation, and safety alignment tasks.meta-llama/Meta-Llama-3-8Bmeta-llama/Meta-Llama-3-8B base model specifically for code generation tasks. It should be loaded using the Hugging Face PEFT library on top of the base LLM.meta-llama/Meta-Llama-3-8B as its base model. Like all large language models, it may generate biased, harmful, or factually incorrect content, and should not be used in critical applications without thorough evaluation and additional safeguards.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5# 1. Load the base model
6base_model_name = "meta-llama/Meta-Llama-3-8B"
7base_model = AutoModelForCausalLM.from_pretrained(
8 base_model_name,
9 torch_dtype=torch.bfloat16, # Llama 3 models often use bfloat16
10 device_map="auto", # Load model onto available devices (GPU if available)
11 low_cpu_mem_usage=True # Optimize CPU memory usage
12)
13
14# 2. Load the LoRI adapter
15# Replace "tomg-group-umd/LoRI-S_code_llama3_rank_64" with the correct model ID if different
16adapter_model_id = "tomg-group-umd/LoRI-S_code_llama3_rank_64"
17adapter_model = PeftModel.from_pretrained(base_model, adapter_model_id)
18
19# 3. Load the tokenizer
20tokenizer = AutoTokenizer.from_pretrained(base_model_name)
21# Set pad_token if not already set, crucial for batching/generation
22if tokenizer.pad_token is None:
23 tokenizer.pad_token = tokenizer.eos_token # Or another appropriate token
24
25# 4. Set the model to evaluation mode
26adapter_model.eval()
27
28# 5. Prepare your input prompt for code generation
29prompt = '''
30def bubble_sort(arr):
31 n = len(arr)
32 for i in range(n - 1):
33 for j in range(0, n - i - 1):
34 if arr[j] > arr[j + 1]:
35 arr[j], arr[j + 1] = arr[j + 1], arr[j]
36 return arr
37
38# Write a docstring for the function above, describing its purpose and parameters.
39'''
40
41# Encode the prompt and move to the model's device
42input_ids = tokenizer.encode(prompt, return_tensors="pt").to(adapter_model.device)
43
44# 6. Generate output
45with torch.no_grad():
46 output_ids = adapter_model.generate(
47 input_ids,
48 max_new_tokens=100,
49 do_sample=True, # Sample outputs
50 temperature=0.01, # Low temperature for less randomness, more deterministic code
51 top_p=0.95, # Nucleus sampling
52 num_return_sequences=1,
53 eos_token_id=tokenizer.eos_token_id,
54 pad_token_id=tokenizer.pad_token_id,
55 )
56
57# Decode and print the generated text
58generated_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
59print(generated_text)
60
61# Optional: Merge adapter weights into the base model for easier deployment
62# merged_model = adapter_model.merge_and_unload()
63# merged_model.save_pretrained("path/to/merged-lori-model")LoRI-S_code_llama3_rank_64 adapter was specifically fine-tuned on the CodeAlpaca dataset for code generation tasks. The LoRI paper also describes experiments on:A are frozen as random projections, and the B matrices are trained densely.LoRI-D training, sparse masks are extracted from the learned B matrices. For LoRI-S models, a high sparsity level (e.g., 90%) is typically applied.LoRI-S_code_llama3_rank_64, is the result of this sparsified training phase.meta-llama/Meta-Llama-3-8Br): 64lora_alpha): 128lora_dropout): 0.05A are fixed as random projections, and the matrices B are sparsified using task-specific masks. This design is aimed at reducing cross-task interference in multi-task learning and mitigating catastrophic forgetting in continual learning scenarios.1@article{zhang2025lori,
2 title={LoRI: Reducing Cross-Task Interference in Multi-Task Low-Rank Adaptation},
3 author={Zhang, Juzheng and You, Jiacheng and Panda, Ashwinee and Goldstein, Tom},
4 journal={arXiv preprint arXiv:2504.07448},
5 year={2025}
6}