MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / step_end

Method step_end

codegeex/mindspore/src/callbacks.py:123–158  ·  view source on GitHub ↗

step end

(self, run_context)

Source from the content-addressed store, hash-verified

121 self.lang = lang
122
123 def step_end(self, run_context):
124 """
125 step end
126 """
127 cb_params = run_context.original_args()
128 current_step = cb_params.cur_step_num + self.has_trained_step
129 if current_step % self.print_per_step != 0:
130 return
131 self.pplMetric.clear()
132 self.validation_loss.clear()
133 if self.parallel_mode in (ParallelMode.SEMI_AUTO_PARALLEL, ParallelMode.AUTO_PARALLEL):
134 context.set_auto_parallel_context(strategy_ckpt_save_file="",
135 strategy_ckpt_load_file=self.strategy_ckpt_save_file)
136 rank_id = 0
137 if self.parallel_mode in (ParallelMode.SEMI_AUTO_PARALLEL,
138 ParallelMode.AUTO_PARALLEL, ParallelMode.DATA_PARALLEL):
139 rank_id = get_rank()
140 print("validation begin")
141 start_time = time.time()
142 out = self.model.eval(self.eval_dataset)
143 end_time = time.time()
144 eval_time = int(end_time - start_time)
145
146 time_str = time.strftime("%Y-%m-%d %H:%M%S", time.localtime())
147 out_str = f"{time_str} == Language {self.lang}; Rank {rank_id} Eval: {out}; eval_time: {eval_time}s"
148 print(out_str)
149 if self.summary_writer is not None:
150 print(f"writing: {out}")
151 tag = "validation_loss" if self.lang is None else f"validaton_loss/{self.lang}"
152 self.summary_writer.add_scalar(
153 tag=tag,
154 scalar_value=out['ppl'],
155 global_step=cb_params.cur_step_num + int(self.has_trained_step),
156 )
157 context.set_auto_parallel_context(strategy_ckpt_save_file=self.strategy_ckpt_save_file,
158 strategy_ckpt_load_file=self.strategy_ckpt_load_file)
159
160
161class SaveCheckpointCallback(Callback):

Callers

nothing calls this directly

Calls 2

clearMethod · 0.45
evalMethod · 0.45

Tested by

no test coverage detected