Memory leakage with high concurrence
Hi! I'm using sympy==1.13.0 with python3.11. I want to judge the correctness of llm answer with sympy, so I write the code below with
os.environ["SYMPY_USE_CACHE"]="no"
os.environ["SYMPY_INT_TRACE"]="no"
golden_expr = sp.simplify(parse_latex(golden_answer.replace("\left", "").replace("\right", ""), strict=True, backend="antlr"))
golden_expr_lamb = sp.lambdify([], golden_expr, "numpy")()
my_expr = sp.simplify(parse_latex(simplified_answer.replace("\left", "").replace("\right", ""), strict=True, backend="antlr"))
my_expr_lamb = sp.lambdify([], my_expr, "numpy")()
# raise NotImplementedError
# print(my_expr.evalf(n=8), my_expr_lamb, golden_expr.evalf(n=8), golden_expr_lamb)
result = 1 if abs(golden_expr_lamb - my_expr_lamb) < 1e-4 else -1
assert isinstance(my_expr, sp.Float) or isinstance(my_expr, sp.Integer) or isinstance(my_expr, sp.Rational) or isinstance(my_expr, sp.RealNumber)
assert isinstance(golden_expr, sp.Float) or isinstance(golden_expr, sp.Integer) or isinstance(golden_expr, sp.Rational) or isinstance(golden_expr, sp.RealNumber)
try:
if golden_expr:
del golden_expr
except:
pass
try:
if golden_expr_lamb:
del golden_expr_lamb
except:
pass
try:
if my_expr:
del my_expr
except:
pass
try:
if my_expr_lamb:
del my_expr_lamb
except:
pass
clear_cache()
gc.collect()
However, I notice the memory usage of my program gradually raise to 700GB and leads to OOM Killed. When I comment the sympy part above with re parse method, the memory usage went normal (about 4GB).
I wonder how to solve it, thanks!
The code is incomplete and does not run. It is missing imports, golden_answer is not defined, etc.
Please provide a complete code example that demonstrates this.
The code is incomplete and does not run. It is missing imports,
golden_answeris not defined, etc.Please provide a complete code example that demonstrates this.
Thank you for your reply!
I've found the issue is raised by some weird expressions during the process, but I cannot extract the expression so I cannot give the minimum reproducable code.
I just feed the output of LLM into evalf func, so maybe it is because my dirty expression?