Text Generation
Transformers
Safetensors
qwen2
code
code-analysis
qwen
fine-tuned
conversational
text-generation-inference
Instructions to use Vilyam888/Code_analyze.1.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Vilyam888/Code_analyze.1.0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Vilyam888/Code_analyze.1.0") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Vilyam888/Code_analyze.1.0") model = AutoModelForCausalLM.from_pretrained("Vilyam888/Code_analyze.1.0", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Vilyam888/Code_analyze.1.0 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Vilyam888/Code_analyze.1.0" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Vilyam888/Code_analyze.1.0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Vilyam888/Code_analyze.1.0
- SGLang
How to use Vilyam888/Code_analyze.1.0 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Vilyam888/Code_analyze.1.0" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Vilyam888/Code_analyze.1.0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Vilyam888/Code_analyze.1.0" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Vilyam888/Code_analyze.1.0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Vilyam888/Code_analyze.1.0 with Docker Model Runner:
docker model run hf.co/Vilyam888/Code_analyze.1.0
Download inference.py from Vilyam888/Code_analyze.1.0: direct link, hf CLI and curl.
- Browser
- Download file 3.13 kB
-
https://huggingface.co/Vilyam888/Code_analyze.1.0/resolve/main/inference.py
- Command line
-
hf download hf://Vilyam888/Code_analyze.1.0/inference.py
-
curl -L -o inference.py https://huggingface.co/Vilyam888/Code_analyze.1.0/resolve/main/inference.py
3.13 kB
| """ | |
| Inference code for Code Analyzer Model | |
| This file enables the "Use this model" button on Hugging Face. | |
| """ | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import torch | |
| def load_model_and_tokenizer(model_name: str): | |
| """Load model and tokenizer""" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_name, | |
| torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32, | |
| device_map="auto", | |
| trust_remote_code=True | |
| ) | |
| return model, tokenizer | |
| def build_input(task, code): | |
| """Build input in the same format as used during training""" | |
| parts = [] | |
| if task.strip(): | |
| parts.append(f"Задача:\n{task.strip()}") | |
| if code.strip(): | |
| parts.append(f"Решение (код):\n```python\n{code.strip()}\n```") | |
| return "\n\n".join(parts) | |
| def generate_response( | |
| model, | |
| tokenizer, | |
| task: str, | |
| code: str, | |
| max_new_tokens: int = 1024, | |
| temperature: float = 0.7, | |
| top_p: float = 0.8, | |
| top_k: int = 20, | |
| repetition_penalty: float = 1.05, | |
| ): | |
| """Generate analysis response for task and student code""" | |
| # Format input in training style | |
| input_text = build_input(task, code) | |
| prompt = f"{input_text}\n\nОтвет:\n" | |
| inputs = tokenizer(prompt, return_tensors="pt").to(model.device) | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=max_new_tokens, | |
| temperature=temperature, | |
| top_p=top_p, | |
| top_k=top_k, | |
| repetition_penalty=repetition_penalty, | |
| do_sample=True, | |
| pad_token_id=tokenizer.eos_token_id | |
| ) | |
| response = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| # Extract only the answer part | |
| if "Ответ:" in response: | |
| response = response.split("Ответ:")[-1].strip() | |
| return response | |
| if __name__ == "__main__": | |
| # Example usage | |
| import json | |
| model_name = "Vilyam888/Code_analyze.1.0" | |
| print("Loading model...") | |
| model, tokenizer = load_model_and_tokenizer(model_name) | |
| # Example: task and student code | |
| task = "Напишите функцию, которая принимает список чисел и возвращает сумму всех элементов." | |
| code = """def sum_list(numbers): | |
| total = 0 | |
| for num in numbers: | |
| total += num | |
| return total""" | |
| print(f"\nЗадача: {task}") | |
| print(f"\nКод студента:\n{code}\n") | |
| print("Generating analysis...") | |
| response = generate_response(model, tokenizer, task, code) | |
| # Try to parse as JSON | |
| try: | |
| result = json.loads(response) | |
| print(f"\nРезультат анализа (JSON):") | |
| print(json.dumps(result, ensure_ascii=False, indent=2)) | |
| except json.JSONDecodeError: | |
| print(f"\nРезультат анализа:\n{response}") | |