Spaces:
Sleeping
Sleeping
Download app.py from VADITYA307/LOGIC-L1: direct link, hf CLI and curl.
- Browser
- Download file 2.12 kB
-
https://huggingface.co/spaces/VADITYA307/LOGIC-L1/resolve/main/app.py
- Command line
-
hf download hf://spaces/VADITYA307/LOGIC-L1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/VADITYA307/LOGIC-L1/resolve/main/app.py
2.12 kB
| import torch | |
| import gradio as gr | |
| import spaces | |
| from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer | |
| from transformers.models.qwen2 import Qwen2Config, Qwen2ForCausalLM | |
| # ========================================== | |
| # LOSSLESS RUNTIME ARCHITECTURE BINDING | |
| # ========================================== | |
| class LogicL1Config(Qwen2Config): | |
| model_type = "logic_l1" | |
| class LogicL1ForCausalLM(Qwen2ForCausalLM): | |
| config_class = LogicL1Config | |
| # Register native architecture cleanly so transformers maps weights perfectly | |
| AutoConfig.register("logic_l1", LogicL1Config) | |
| AutoModelForCausalLM.register(LogicL1Config, LogicL1ForCausalLM) | |
| MODEL_ID = "VADITYA307/Logic-L1" | |
| print("Loading AROM Logic L1 with lossless weight mapping...") | |
| tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=False) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| MODEL_ID, | |
| torch_dtype=torch.float16, | |
| trust_remote_code=False | |
| ) | |
| def predict(message, history): | |
| model.to("cuda") | |
| messages = [] | |
| for user_msg, bot_msg in history: | |
| messages.append({"role": "user", "content": user_msg}) | |
| messages.append({"role": "assistant", "content": bot_msg}) | |
| messages.append({"role": "user", "content": message}) | |
| prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) | |
| inputs = tokenizer(prompt, return_tensors="pt").to("cuda") | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=512, | |
| temperature=0.3, | |
| top_p=0.95, | |
| repetition_penalty=1.15, | |
| do_sample=True, | |
| pad_token_id=tokenizer.eos_token_id | |
| ) | |
| response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True) | |
| return response.replace("<|im_end|>", "").strip() | |
| demo = gr.ChatInterface( | |
| fn=predict, | |
| title="AROM Logic L1", | |
| description="State-of-the-art proprietary artificial intelligence engineered exclusively by Aditya 'Aadi' at AROM Labs India." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |