Add the following information in bold to the QWEN3_for_PyTorch_2.7_code/mindspeed_llm/training/training.py code to inject a fault. The new code obtains the iteration position and fault rank based on the environment variable RAISE_UCE_ERROR_STEP_AND_RANK.import os
import ast
...
GLB_CNT = 0
def train(forward_step_func, model, optimizer, opt_param_scheduler,
train_data_iterator, valid_data_iterator,
process_non_loss_data_func, config):
"""Train the model function."""
args = get_args()
timers = get_timers()
...
while iteration < args.train_iters:
…
num_microbatches = get_num_microbatches()
update_num_microbatches(args.consumed_train_samples, consistency_check=True)
global GLB_CNT
cur_rank = torch.distributed.get_rank()
uce_env = os.getenv("RAISE_UCE_ERROR_STEP_AND_RANK", "{}")
uce_step_rank = ast.literal_eval(uce_env)
if iteration in uce_step_rank and cur_rank == uce_step_rank[iteration] and GLB_CNT < iteration:
GLB_CNT = iteration
print(f"############# rank:{cur_rank} start UCE error #############")
raise RuntimeError('UCE ERROR')
args.curr_iteration = iteration
…