#!/usr/bin/env python3 """ Deployxa LM 1.0 - Sample Inference Script. Demonstrates loading the fine-tuned Deployxa LM 1.0 adapter on top of Qwen/Qwen2.5-Coder-1.5B-Instruct using PyTorch, Transformers, and PEFT. Brand: Deployxa Cloud Inc. (https://deployxa.com) Product: Deployxa LM 1.0 Tagline: Build. Deploy. Scale. """ import sys import json import argparse from pathlib import Path try: import torch from transformers import AutoTokenizer, AutoModelForCausalLM from peft import PeftModel except ImportError: print("Error: PyTorch, Transformers, or PEFT not installed.") print("Install dependencies with: pip install torch transformers peft accelerate") sys.exit(1) BASE_MODEL_ID = "Qwen/Qwen2.5-Coder-1.5B-Instruct" # Default to current folder if adapter_model.safetensors exists here, else Hugging Face hub DEFAULT_ADAPTER = str(Path(__file__).resolve().parent) if (Path(__file__).resolve().parent / "adapter_model.safetensors").exists() else "deployxa/deployxa-lm-1.0" APPROVED_CANONICAL_CATEGORIES = [ "BUILD_COMPILATION_FAILED", "CONTAINER_STARTUP_CRASH", "HEALTH_CHECK_FAILURE", "DEPENDENCY_INSTALLATION_FAILED", "RESOURCE_EXHAUSTION", "NETWORKING_ROUTING_ERROR", "DATABASE_MIGRATION_FAILURE", "PORT_BINDING_CONFLICT", "INVALID_APPLICATION_CONFIG" ] def format_diagnostic_prompt(template_id: str, telemetry_logs: str) -> str: """Constructs the official Deployxa LM 1.0 diagnostic prompt with pinned taxonomy.""" categories_str = ", ".join(APPROVED_CANONICAL_CATEGORIES) return ( "<|im_start|>system\n" "You are DXA-LM, Deployxa's specialist deployment diagnostic and repair advisor.\n" "Analyze the provided deployment logs and telemetry. Determine the deployment status, " "exact root cause category, and whether evidence is sufficient to make a diagnosis.\n" f"Allowed root cause categories: {categories_str}.\n" "Format response strictly as JSON with keys: deployment_status, root_cause_category, " "confidence, evidence, reasoning_summary, abstain, abstention_reason.<|im_end|>\n" "<|im_start|>user\n" f"Deployment Logs ({template_id}):\n" f"{telemetry_logs}\n\n" "Diagnose deployment:<|im_end|>\n" "<|im_start|>assistant\n" ) def main(): parser = argparse.ArgumentParser(description="Run Deployxa LM 1.0 Diagnostic Inference") parser.add_argument("--adapter", default=DEFAULT_ADAPTER, help="Path or Hugging Face repo ID for adapter") parser.add_argument("--base-model", default=BASE_MODEL_ID, help="Base model identifier") parser.add_argument("--template", default="solid-start", help="Service or framework template name") parser.add_argument("--log", default=None, help="Path to error log file (or pass raw text)") args = parser.parse_args() sample_log = """ 2026-10-18T10:15:20Z [server] Starting HTTP listener on port 3000... 2026-10-18T10:15:20Z [server] uncaughtException: Error: listen EADDRINUSE: address already in use :::3000 at Server.setupListenHandle [as _listen2] (node:net:1855:16) at listenInCluster (node:net:1903:12) at Server.listen (node:net:2001:7) 2026-10-18T10:15:21Z [systemd] app.service: Main process exited, code=exited, status=1/FAILURE """ if args.log: p = Path(args.log) if p.exists() and p.is_file(): sample_log = p.read_text(encoding="utf-8", errors="ignore") else: sample_log = args.log device = "cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu") print(f"Loading base model '{args.base_model}' on {device}...") tokenizer = AutoTokenizer.from_pretrained(args.base_model, trust_remote_code=True) base_model = AutoModelForCausalLM.from_pretrained( args.base_model, torch_dtype=torch.float16 if device != "cpu" else torch.float32, device_map="auto" if device == "cuda" else None, trust_remote_code=True ) if device != "cuda": base_model.to(device) print(f"Attaching Deployxa LM 1.0 adapter '{args.adapter}'...") model = PeftModel.from_pretrained(base_model, args.adapter) model.eval() prompt = format_diagnostic_prompt(args.template, sample_log) inputs = tokenizer(prompt, return_tensors="pt").to(device) print("Running neural diagnostic inference...") with torch.no_grad(): output_ids = model.generate( **inputs, max_new_tokens=400, temperature=0.01, do_sample=False, pad_token_id=tokenizer.eos_token_id ) response_text = tokenizer.decode(output_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip() # Strip markdown code blocks if wrapped if response_text.startswith("```json"): response_text = response_text[7:] elif response_text.startswith("```"): response_text = response_text[3:] if response_text.endswith("```"): response_text = response_text[:-3] print("\n" + "=" * 60) print("DEPLOYXA LM 1.0 PREDICTION OUTPUT:") print("=" * 60) try: data = json.loads(response_text) print(json.dumps(data, indent=2)) except Exception: print(response_text) if __name__ == "__main__": main()