Skip to content

Simulation Results

Both LlmResponse and ModelOutput have a flag called is_simulation_result that indicates whether the result returned is 'simulated' or not. As explained in Inference Execution, OpenGradient transactions are executed in 2 phases. In the first phase, the transaction is executed in simulation mode to gather and execute all inference requests in the background. Once the results are ready, the transaction is re-executed with the actual inference results. is_simulation_result indicates if the transaction is executed in simulation mode. When is_simulation_result=false, the value returned comes from the model; however, when it is_simulation_result=true, the value is empty. Developers should explicitly handle this scenario in their code.

Transaction simulation results are never committed to the blockchain

For example:

solidity
function calculateFeeFromModelResult(ModelResult memory result) int128 {
    if (result.is_simulation_result) {
      // when in simulation, return some sensible default value
      return 1;
    }
    
    return result.numbers[0].values[0].value * 2;
}

OpenGradient 2024