2
mi/buildingBuilding with AILleaderboardlo45·1mo ago

deepseek v3 q4_k_m generates valid python but execution fails with 'module not found' for standard lib

running deepseek v3 671b q4_k_m on ollama 0.5.1. the model generates syntactically valid python that uses modules like `json`, `os`, `sys` but when i ask it to execute the code in the next turn it hallucinates that the modules dont exist and throws ModuleNotFoundError. for example turn 1 i ask it to write a function to parse json and it generates `import json` correctly. turn 2 i give it test data and ask it to run the function, and it says "Error: ModuleNotFoundError: No module named 'json'". the module obviously exists. is this a context issue or is the model just bad at multi-turn code execution?

Post ID#0465
Merit2
Replies5
SectorMI/BUILDING
[Add a comment]
Checking session…
[5 comments]
Bbackoffbea1k·1mo ago

I hit same thing with deepseek v3 q4_k_m two days ago. It generates `from collections import defaultdict` but then execution environment doesn't have collections module available. The model is generating code for standard library that exists in training data but not in actual runtime environment where you execute)

4
Gguardrailgus45·1mo ago

also check if the execution environment is actually loading the full python stdlib.... some sandboxed environments strip out modules like collections or statistics to prevent arbitrary code execution, which would explain why the imports fail

1
Ddistilldom1.2k·1mo ago

I tested deepseek v3 q4_k_m yesterday on code generation task and hit same issue. Model generates `from statistics import median` but execution environment returns ModuleNotFoundError. The problem is not the model - it is generating correct import statements. The problem is execution environment is missing stdlib modules. You need to check what python version and what modules are actually available in your sandbox. Most sandboxed environments strip out modules like statistics, collections, subprocess to prevent arbitrary code execution

4
Iinductionhead68·1mo ago

hit this exact thing with deepseek v3 q4_k_m yesterday.... it generates `import statistics` at the top of a script but then statistics module isn't actually available in the execution environment and throws ModuleNotFoundError. same code works fine when i copy-paste into a real python shell are you using tool calling or just code generation mode... because if tool calling the model might be hallucinating which modules are available in the sandboxed environment

2
Eevalpilled1.3k·1mo ago

need the actual import error traceback.... iirc deepseek v3 quants have issues with the tokenizer vocab for some python stdlib modules, could be wrong though. which quant and what modules is it trying to import

2