pass a prompt in from stdin for inference

This commit is contained in:
Wing Lian
2023-06-10 15:07:40 -04:00
parent 01248253a3
commit c4e4f8115c
2 changed files with 23 additions and 5 deletions

View File

@@ -495,6 +495,11 @@ Pass the appropriate flag to the train command:
```bash ```bash
--inference --base_model ./completed-model --inference --base_model ./completed-model
``` ```
- Full weights finetune w/ a prompt from a text file:
```bash
cat /tmp/prompt.txt | python scripts/finetune.py configs/your_config.yml \
--base_model ./completed-model --inference --prompter=None --load_in_8bit=True
```
### Merge LORA to base ### Merge LORA to base

View File

@@ -71,7 +71,11 @@ def do_inference(cfg, model, tokenizer, prompter="AlpacaPrompter"):
if not (cfg.special_tokens and token in cfg.special_tokens): if not (cfg.special_tokens and token in cfg.special_tokens):
tokenizer.add_special_tokens({token: symbol}) tokenizer.add_special_tokens({token: symbol})
prompter_module = getattr(importlib.import_module("axolotl.prompters"), prompter) prompter_module = None
if prompter:
prompter_module = getattr(
importlib.import_module("axolotl.prompters"), prompter
)
while True: while True:
print("=" * 80) print("=" * 80)
@@ -79,9 +83,12 @@ def do_inference(cfg, model, tokenizer, prompter="AlpacaPrompter"):
instruction = get_multi_line_input() instruction = get_multi_line_input()
if not instruction: if not instruction:
return return
prompt: str = next( if prompter_module:
prompter_module().build_prompt(instruction=instruction.strip("\n")) prompt: str = next(
) prompter_module().build_prompt(instruction=instruction.strip("\n"))
)
else:
prompt = instruction.strip()
batch = tokenizer(prompt, return_tensors="pt", add_special_tokens=True) batch = tokenizer(prompt, return_tensors="pt", add_special_tokens=True)
print("=" * 40) print("=" * 40)
model.eval() model.eval()
@@ -242,7 +249,13 @@ def train(
if "inference" in kwargs: if "inference" in kwargs:
logging.info("calling do_inference function") logging.info("calling do_inference function")
do_inference(cfg, model, tokenizer) inf_kwargs: Dict[str, Any] = {}
if "prompter" in kwargs:
if kwargs["prompter"] == "None":
inf_kwargs["prompter"] = None
else:
inf_kwargs["prompter"] = kwargs["prompter"]
do_inference(cfg, model, tokenizer, **inf_kwargs)
return return
if "shard" in kwargs: if "shard" in kwargs: