LLM4Decompile icon indicating copy to clipboard operation
LLM4Decompile copied to clipboard

Question,大模型使用问题

Open duhang1996 opened this issue 1 year ago • 6 comments

模型:llm4decompile-9b-v2 下图是我用demo.py跑出的结果: image

是不是只能用这种执行demo.py脚本的方式使用大模型,目前有没有别的方式?

duhang1996 avatar Dec 10 '24 09:12 duhang1996

sample_pseudo.txt sample_result.txt

使用模型:llm4decompile-9b-v2模型 反编译libm-2.28.so二进制文件,sample_result是大模型输出的结果,函数内容不全,这是什么原因呢?

duhang1996 avatar Dec 11 '24 06:12 duhang1996

模型使用可以用hf的model.generate,也可以用vllm推理(参考evaluation脚本),或者转换成gguf格式(hf也有朋友已经转换成该格式,我们暂时还没有尝试过)使用ollama/lmstudio推理。demo只是展示最直观简便的方式预处理-输入模型-输出结果。

内容不全应该是outputs = model.generate(**inputs, max_new_tokens=2048)设置。但训练样本大多是2K附近长度,4k长函数估计不及预期。我们在准备更长更强的模型。

albertan017 avatar Dec 11 '24 07:12 albertan017

@albertan017 执行evaluation脚本出现:(https://github.com/albertan017/LLM4Decompile/blob/main/evaluation/run_evaluation_llm4decompile_vllm.py)脚本 image 脚本:python run_evaluation_llm4decompile_vllm.py --model_path ../../llm4decompile-9b-v2 --testset_path ../decompile-eval/decompile-eval-executable-gcc-ghidra.json --gpus 4 --max_total_tokens 8192 --max_new_tokens 512 --repeat 1 --num_workers 16 --gpu_memory_utilization 0.82 --temperature 0

是不是我的脚本参数有问题

duhang1996 avatar Dec 11 '24 07:12 duhang1996

模型使用可以用hf的model.generate,也可以用vllm推理(参考evaluation脚本),或者转换成gguf格式(hf也有朋友已经转换成该格式,我们暂时还没有尝试过)使用ollama/lmstudio推理。demo只是展示最直观简便的方式预处理-输入模型-输出结果。

内容不全应该是outputs = model.generate(**inputs, max_new_tokens=2048)设置。但训练样本大多是2K附近长度,4k长函数估计不及预期。我们在准备更长更强的模型。

max_new_tokens换成4096也是显示不全。

duhang1996 avatar Dec 11 '24 11:12 duhang1996

模型使用可以用hf的model.generate,也可以用vllm推理(参考evaluation脚本),或者转换成gguf格式(hf也有朋友已经转换成该格式,我们暂时还没有尝试过)使用ollama/lmstudio推理。demo只是展示最直观简便的方式预处理-输入模型-输出结果。 内容不全应该是outputs = model.generate(**inputs, max_new_tokens=2048)设置。但训练样本大多是2K附近长度,4k长函数估计不及预期。我们在准备更长更强的模型。

max_new_tokens换成4096也是显示不全。

不太能复现你的情况,我尝试了增加max_length,但结果一致。

使用模型:llm4decompile-9b-v2模型 代码:

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

fileName = "sample"

model_path = 'LLM4Binary/llm4decompile-6.7b-v2' # V2 Model

tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16).cuda()

with open(fileName +'.pseudo','r') as f:#optimization level O0
    asm_func = f.read()
inputs = tokenizer(asm_func, return_tensors="pt").to(model.device)
with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=4048)### max length to 4096, max new tokens should be below the range
c_func_decompile = tokenizer.decode(outputs[0][len(inputs[0]):-1])

print(f'refined function:\n{c_func_decompile}')

以下是model.generate的结果:

refined function:
long double
expl(long double x)
{
 long double y, z, w, t1, t2, u, v, r, s, c, d, e, f, g, h, i, j, k, l, m;
 int ix, hx, lx, ix1, iy;


 if (x == 0.0)
  return (1.0);
 if (x != x)
  return (x + x);


 ix = *(1 + (int *)&x);







 ix &= 0x7fffffff;






 if (ix >= 0x7ff00000) {
  if (((ix & 0xfffff) | ((ix >> 12) & 0x7ff00000)) == 0x7ff00000)
   return (x * 0.0 + 1.0);
  return (x * 0.0);
 }


 if (ix < 0x3e300000) {
  if (ix < 0x33800000) {
   if (ABS(x) < 1.00000000000000011102230246251565404236316680908203125e-292)
    return (1.0);
   z = x * x;
   w = z * x;
   iy = 1 - (ix >> 20);
   return (1.0 + w * (1.0 + iy * (0.5 + w * (0.33333333333333331111111111111111 +
       w * 0.25 * (1.0 + iy * (0.2 + w * 0.16666666666666666666666666666667))))));
  }
  iy = (ix >> 20) - 1023;
  ix &= 0x000fffff;
  ix |= (1 << 20);
  x = *(1 + (int *)&ix) - 1.0;
  if (ix >= 0x7fe00000)
   return (x * 0.0 + 1.0);
  if (iy >= 20) {
   w = 1.0 - x;
   return (w * 0.0);
  }
 } else {
  iy = (ix >> 20) - 1023;
  ix &= 0x000fffff;
 }


 if (ix >= 0x7e900000) {
  if (ix >= 0x7fd00000)
   return (x * 0.0 + 1.0);
  if (iy >= 709) {
   w = 1.0 - x;
   return (w * 0.0);
  }
 }


 hx = ix >> 4;
 lx = (ix & 0xf) << 20;
 if (hx >= 0x3ff) {
  u = 0.0;
 } else {
  if (hx < 0x3fe) {
   ix1 = (hx & 0x800) >> 11;
   hx &= 0x7fe;
   u = ldexpl((long double)hx, -20);
   t1 = u * (long double)0x1.8p52;
   t2 = u * -(long double)0.48074069840786023350695868215571167910752964391708255675837672578125e-29;
   c = t1 + t2;
   d = (long double)0.5 * c;
   e = (long double)0.5 - d;
   f = (long double)1.0 + e;
   g = f - d;
   h = f - (c + g);
   ix1 |= (ix >> 12) & 0x7ff;
   iy += ix1;
  } else {
   ix1 = (hx & 0x400) >> 10;
   hx &= 0x3ff;
   u = ldexpl((long double)hx, -20);
   t1 = u * (long double)0x1.8p52;
   t2 = u * -(long double)0.48074069840786023350695868215571167910752964391708255675837672578125e-29;
   c = t1 + t2;
   d = (long double)0.5 * c;
   e = (long double)0.5 - d;
   f = (long double)1.0 + e;
   g = f - d;
   h = f - (c + g);
   ix1 |= (ix >> 12) & 0x7ff;
   iy += ((ix1 & 0x7ff) | ((ix1 >> 11) & 0x7800));
  }
  k = ldexpl((long double)iy, -52);
  if (lx == 0) {
   j = k;
  } else {
   volatile long double dk = k, *ip = (&j);

   *ip = dk * ldexpl((long double)lx, -52);
   hx = *(1 + (int *)&j);
   hx &= 0x7fffffff;
   if (hx < 0x3fff0000) {
    if ((hx & 0xfffff) | ((hx >> 10) & 0x7ff00000))
     return (k * x);
   }
   j = k;
  }
  if (iy > 0) {
   v = j + k;
   w = v - k;
   y = v - (j + w);
   return (y + x * k);
  }
  v = j - k;
  w = v - k;
  y = v - (j + w);
  return (x * y + k * j);
 }


 if (iy > 0) {
  z = ldexpl((long double)1, iy);
  return (x * z);
 }


 z = ldexpl((long double)1, -iy);
 return (z * expl(x));
}

albertan017 avatar Dec 14 '24 14:12 albertan017

@albertan017 执行evaluation脚本出现:(https://github.com/albertan017/LLM4Decompile/blob/main/evaluation/run_evaluation_llm4decompile_vllm.py)脚本%E8%84%9A%E6%9C%AC) image 脚本:python run_evaluation_llm4decompile_vllm.py --model_path ../../llm4decompile-9b-v2 --testset_path ../decompile-eval/decompile-eval-executable-gcc-ghidra.json --gpus 4 --max_total_tokens 8192 --max_new_tokens 512 --repeat 1 --num_workers 16 --gpu_memory_utilization 0.82 --temperature 0

是不是我的脚本参数有问题

这里有什么问题吗?截图中基本复现论文中llm4decompile-9b-v2的结果。 各类的error是编译和执行测试的error(对应的是不能执行的那一部分数据报错,我们没有屏蔽编译和执行中的报错)

albertan017 avatar Dec 14 '24 15:12 albertan017