deepseekv3 / proxy_model.py
sapthesh's picture
Update proxy_model.py
fb6e979 verified
import os
import requests
import torch
from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM
class RemoteModelProxy:
def __init__(self, model_id):
self.model_id = model_id
self.tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
# Load the configuration and remove the quantization configuration
config = AutoConfig.from_pretrained(model_id, trust_remote_code=True)
if hasattr(config, 'quantization_config'):
del config.quantization_config
self.config = config
self.model = AutoModelForCausalLM.from_pretrained(model_id, config=self.config, trust_remote_code=True)
def classify_text(self, text):
inputs = self.tokenizer(text, return_tensors="pt", padding=True, truncation=True)
logits = self.model(**inputs)
probabilities = torch.softmax(logits, dim=-1).tolist()[0]
predicted_class = torch.argmax(logits, dim=-1).item()
return {
"Predicted Class": predicted_class,
"Probabilities": probabilities
}
if __name__ == "__main__":
model_id = "deepseek-ai/DeepSeek-V3"
proxy = RemoteModelProxy(model_id)
result = proxy.classify_text("Your input text here")
print(result)