RayNene/Loop-DFS-Qwen-Merged
LOOP DFS Qwen Merged 16-bit Model
Revised README.md
# LOOP DFS Qwen Merged 16-bit Model
This repository contains a merged 16-bit Qwen model fine-tuned for LOOP DFS assistance.
The model is designed to answer questions about LOOP DFS company information, products, services, partnerships, and documented API behavior.
## Generation configuration
The recommended generation settings are:
- `max_new_tokens`: 512
- `temperature`: 0.2
- `top_p`: 0.9
- `repetition_penalty`: 1.05
The complete system prompt is stored in `system_prompt.txt`.
Machine-readable inference settings are stored in `deployment_config.json`.
## Quick start
Install the required packages:
pip install -U transformers accelerate huggingface_hub sentencepiece torch
Load the model and its system prompt directly from this public repository:
import torch from huggingfacehub import hfhub_download from transformers import AutoModelForCausalLM, AutoTokenizer
MODELID = "RayNene/Loop-DFS-Qwen-Merged" MAXNEW_TOKENS = 512
Load the complete system prompt from the repository.
systempromptpath = hfhubdownload( repoid=MODELID, filename="system_prompt.txt", )
with open(systempromptpath, "r", encoding="utf-8") as file: SYSTEM_PROMPT = file.read().strip()
if not SYSTEMPROMPT: raise RuntimeError("systemprompt.txt is empty.")
Select an appropriate inference data type.
if torch.cuda.isavailable(): inferencedtype = ( torch.bfloat16 if torch.cuda.isbf16supported() else torch.float16 ) else: inference_dtype = torch.float32
Load the tokenizer.
tokenizer = AutoTokenizer.frompretrained( MODELID, trustremotecode=True, )
if tokenizer.padtokenid is None: tokenizer.padtoken = tokenizer.eostoken
Load the merged model.
model = AutoModelForCausalLM.frompretrained( MODELID, torchdtype=inferencedtype, devicemap="auto", trustremotecode=True, lowcpumemusage=True, )
model.eval()
Configure valid end-of-response tokens.
terminator_ids = []
for tokenid in [ tokenizer.eostokenid, tokenizer.converttokenstoids("<|imend|>"), ]: if tokenid is None: continue
if tokenid == tokenizer.unktoken_id: continue
if tokenid not in terminatorids: terminatorids.append(tokenid)
if not terminator_ids: raise RuntimeError("No valid generation terminator was found.")
def cleananswer(answer): """Prevent accidental generation of another conversation turn.""" stopmarkers = [ "<|imend|>", "<|imstart|>system", "<|imstart|>user", "<|imstart|>assistant", "\nSystem:", "\nUser:", ]
positions = [ answer.find(marker) for marker in stop_markers if answer.find(marker) >= 0 ]
if positions: answer = answer[:min(positions)]
return answer.strip()
def ask(question, history=None): """Generate one LOOP DFS assistant response.""" if not isinstance(question, str) or not question.strip(): raise ValueError("The question must be a non-empty string.")
if history is None: history = []
messages = [ { "role": "system", "content": SYSTEM_PROMPT, }, *history, { "role": "user", "content": question.strip(), }, ]
prompt = tokenizer.applychattemplate( messages, tokenize=False, addgenerationprompt=True, )
inputs = tokenizer( prompt, returntensors="pt", addspecial_tokens=False, )
inputdevice = model.getinput_embeddings().weight.device
inputs = { name: tensor.to(input_device) for name, tensor in inputs.items() }
promptlength = inputs["inputids"].shape[1]
with torch.inferencemode(): output = model.generate( **inputs, maxnewtokens=MAXNEWTOKENS, dosample=True, temperature=0.2, topp=0.9, repetitionpenalty=1.05, eostokenid=terminatorids, padtokenid=tokenizer.padtokenid, usecache=True, )
generatedtokens = output[0, promptlength:]
answer = tokenizer.decode( generatedtokens, skipspecial_tokens=True, )
return clean_answer(answer)
answer = ask("Who is the CEO of LOOP DFS Kenya?") print(answer)
## Interactive chat
The following starter code maintains conversation history and uses the complete system prompt loaded from `system_prompt.txt`:
conversation = []
print("LOOP DFS Assistant") print("Commands: clear | exit | quit") print()
while True: try: user_message = input("You: ").strip()
if not user_message: continue
command = user_message.lower()
if command in {"exit", "quit"}: print("Chat ended.") break
if command == "clear": conversation.clear() print("Conversation history cleared.") print() continue
response = ask( question=user_message, history=conversation, )
print(f"\nLOOP DFS Assistant: {response}\n")
conversation.extend( [ { "role": "user", "content": user_message, }, { "role": "assistant", "content": response, }, ] )
except KeyboardInterrupt: print("\nChat ended.") break
## Google Colab starter
In a new Google Colab notebook:
1. Select **Runtime → Change runtime type → GPU**.
2. Run the installation cell:
!pip -q install -U transformers accelerate huggingface_hub sentencepiece
3. Run the Python code from the **Quick start** section.
4. Run the **Interactive chat** section.
No Hugging Face token is required because the repository is public.
## Loading the deployment configuration
Applications can load the recommended generation configuration directly from `deployment_config.json`:
import json from huggingfacehub import hfhub_download
configpath = hfhubdownload( repoid="RayNene/Loop-DFS-Qwen-Merged", filename="deployment_config.json", )
with open(configpath, "r", encoding="utf-8") as file: deploymentconfig = json.load(file)
print(deployment_config)
It can then be applied during generation:
output = model.generate( **inputs, maxnewtokens=deploymentconfig.get( "maxnewtokens", 512, ), dosample=deploymentconfig.get( "dosample", True, ), temperature=deploymentconfig.get( "temperature", 0.2, ), topp=deploymentconfig.get( "topp", 0.9, ), repetitionpenalty=deploymentconfig.get( "repetitionpenalty", 1.05, ), eostokenid=terminatorids, padtokenid=tokenizer.padtokenid, use_cache=True, )
## Deployment requirements
Current company facts, product terms, fees, eligibility requirements, leadership information, partnerships, and API behavior should be supplied through approved retrieval sources or verified tools.
Authentication and authorization must be handled outside the conversation. The assistant must never collect passwords, PINs, OTPs, CVVs, secret keys, access tokens, or other authentication credentials through chat.
Financial transactions must be validated by application code, summarized for the user, and explicitly confirmed through an approved secure flow. The model must not be used as the transaction authorization layer.
## Repository files
- `system_prompt.txt` — complete production system prompt
- `deployment_config.json` — recommended generation and deployment settings
- `config.json` — model architecture configuration
- `generation_config.json` — model generation configuration, when included
- `tokenizer_config.json` — tokenizer configuration
- `tokenizer.json` — tokenizer vocabulary and rules, when included
- `*.safetensors` — merged model weights