Transformers
HFInference
¶
Class for running HF model inference locally.
Source code in ragfit/models/hf.py
__init__(model_name_or_path: str, torch_dtype, device_map, instruction: Path, instruct_in_prompt: False, template: Path = None, lora_path=None, generation=None, task='text-generation', **kwargs)
¶
Initialize a HF model, with optional LORA adapter.
Parameters:
-
model_name_or_path(str) –HF model name or path.
-
torch_dtype(str) –torch dtype for the model.
-
device_map–device map for the model.
-
instruction(Path) –path to the instruction file.
-
instruct_in_prompt(bool) –whether to include the instruction in the prompt for models without system role.
-
template(Path, default:None) –path to a prompt template file if tokenizer does not include chat template. Optional.
-
lora_path(Path, default:None) –path to the LORA adapter.
-
generation(dict, default:None) –generation kwargs.
-
task(str, default:'text-generation') –task for the pipeline.
Source code in ragfit/models/hf.py
generate(prompt: str) -> str
¶
Given an input, generate a response.
Source code in ragfit/models/hf.py
HFTrain
¶
Class for training HF models locally.
Source code in ragfit/models/hf.py
__init__(model_name_or_path, torch_dtype, device_map, lora: LoraConfig = None, generation=None, completion_start: str = '', instruction_in_prompt=None, max_sequence_len=None, **kwargs)
¶
Parameters:
-
model_name_or_path–str - HF model name or path.
-
torch_dtype–str - torch dtype for the model.
-
device_map–dict - device map for the model.
-
lora(LoraConfig, default:None) –dict - LoRA adapter config.
-
generation–dict - generation kwargs.
-
completion_start(str, default:'') –str - used to find the start of the completion in the prompt.
-
instruction_in_prompt–bool - whether to include the instruction in the prompt for models without system role.