Update inference.py

Fix potential bug with MAX_QUERY_ID