asm2asm-deepseek1.3b-xtokenizer-arm is designed to assist developers in converting x86 assembly instructions to ARM assembly. Leveraging the capabilities of the base model, this fine-tuned variant enhances accuracy and efficiency in assembly code transpilation tasks.
Intended Use
This model is intended for:
Assembly Code Conversion: Assisting developers in translating x86 assembly instructions to ARM architecture.
Educational Purposes: Helping learners understand the differences and translation mechanisms between x86 and ARM assembly.
Code Optimization: Facilitating optimization processes by converting and refining assembly code across architectures.
Limitations
Dataset Specificity: The model is fine-tuned on a specific dataset, which may limit its performance on assembly instructions outside the training distribution.
Complex Instructions: May struggle with highly complex or unconventional assembly instructions not well-represented in the training data.
Error Propagation: Inaccuracies in the generated ARM code can lead to functional discrepancies or bugs if not reviewed.
Training Data
Detailed information about the training dataset is required.
Training Procedure
Training Hyperparameters
The model was trained with the following hyperparameters:
Learning Rate: 0.0002
Training Batch Size: 1
Evaluation Batch Size: 8
Seed: 42
Gradient Accumulation Steps: 4
Total Training Batch Size: 4
Optimizer: Adam (betas=(0.9, 0.999), epsilon=1e-08)
Learning Rate Scheduler: Linear
Number of Epochs: 2
Usage
All models and datasets are available on Hugging Face. Below is an example of how to use the best model for converting x86 assembly to ARM.
Inference Code
python
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from tqdm import tqdm
45# Replace 'hf_token' with your Hugging Face token6hf_token ="your_hf_token_here"78model_name ="ahmedheakl/asm2asm-deepseek1.3b-xtokenizer-arm"910instruction ="""<|begin▁of▁sentence|>You are a helpful coding assistant specialized in converting from x86 to ARM assembly.
11### Instruction:
12Convert this x86 assembly into ARM
13```asm
14{asm_x86}
15"```"
16### Response:
17```asm
18{asm_arm}
19"""2021# Load the model22model = AutoModelForCausalLM.from_pretrained(23 model_name,24 token=hf_token,25 device_map="auto",26 torch_dtype=torch.bfloat16,27)2829model.config.use_cache =True3031# Load the tokenizer32tokenizer = AutoTokenizer.from_pretrained(33 model_name,34 trust_remote_code=True,35 token=hf_token,36)3738definference(asm_x86:str)->str:39 prompt = instruction.format(asm_x86=asm_x86, asm_arm="")40 inputs = tokenizer(prompt, return_tensors="pt").to("cuda")41 generated_ids = model.generate(42**inputs,43 use_cache=True,44 num_return_sequences=1,45 max_new_tokens=8000,46 do_sample=False,47 num_beams=4,48 eos_token_id=tokenizer.eos_token_id,49 pad_token_id=tokenizer.pad_token_id,50)51 outputs = tokenizer.batch_decode(generated_ids)[0]52 torch.cuda.empty_cache()53 torch.cuda.synchronize()54return outputs.split("```asm\n")[-1].split(f"```{tokenizer.eos_token}")[0]5556# Example usage57x86 ="DWORD PTR -248[rbp] movsx rdx"58converted_arm = inference(x86)59print(converted_arm)
Experiments and Results
Model
Average Edit Distance (↓)
Exact Match (↑)
Test Accuracy (↑)
GPT4o
1296
0%
8.18%
DeepSeekCoder2-16B
1633
0%
7.36%
Yi-Coder-9B
1653
0%
6.33%
Yi-Coder-1.5B
275
16.98%
49.69%
DeepSeekCoder-1.3B
107
45.91%
77.23%
DeepSeekCoder-1.3B-xTokenizer-int4
119
46.54%
72.96%
DeepSeekCoder-1.3B-xTokenizer-int8
96
49.69%
75.47%
DeepSeekCoder-1.3B-xTokenizer
165
50.32%
79.25%
Table: Comparison of models' performance on the x86 to ARM transpilation task, measured by Edit Distance (lower is better), Exact Match (higher is better), and Test Accuracy (higher is better). The top section lists pre-existing models, while the bottom section lists models trained by us. The best results in each metric are highlighted in bold.
If you use this model in your research, please cite it as follows:
@article{heakl2024cisc,
title={From CISC to RISC: language-model guided assembly transpilation},
author={Heakl, Ahmed and Abi, Chaimaa and Hossam, Rania and Mahmoud, Abdulrahman},
journal={arXiv preprint arXiv:2411.16341},
year={2024}
}