3030
3131logger = get_logger ()
3232
33+ is_spaces = True if 'SPACE_ID' in os .environ else False
34+ if is_spaces :
35+ is_shared_ui = True if 'modelscope/swift' in os .environ ['SPACE_ID' ] else False
36+ else :
37+ is_shared_ui = False
38+
3339
3440class LLMTrain (BaseUI ):
3541
@@ -214,7 +220,10 @@ def do_build_ui(cls, base_tab: Type['BaseUI']):
214220 value = default_device ,
215221 scale = 8 )
216222 gr .Textbox (elem_id = 'gpu_memory_fraction' , scale = 4 )
217- gr .Checkbox (elem_id = 'dry_run' , value = False , scale = 4 )
223+ if is_shared_ui :
224+ gr .Checkbox (elem_id = 'dry_run' , value = True , interactive = False , scale = 4 )
225+ else :
226+ gr .Checkbox (elem_id = 'dry_run' , value = False , scale = 4 )
218227 submit = gr .Button (elem_id = 'submit' , scale = 4 , variant = 'primary' )
219228
220229 Save .build_ui (base_tab )
@@ -232,7 +241,7 @@ def do_build_ui(cls, base_tab: Type['BaseUI']):
232241 [cls .element ('runtime_tab' ), cls .element ('log' )]).then (
233242 cls .train_studio ,
234243 [value for value in cls .elements ().values () if not isinstance (value , (Tab , Accordion ))],
235- [cls .element ('log' )] + Runtime .all_plots ,
244+ [cls .element ('log' )] + Runtime .all_plots + [ cls . element ( 'running_cmd' )] ,
236245 queue = True )
237246 else :
238247 submit .click (
@@ -342,14 +351,17 @@ def train(cls, *args):
342351 @classmethod
343352 def train_studio (cls , * args ):
344353 run_command , sft_args , other_kwargs = cls .train (* args )
345- if cls . is_studio :
354+ if not other_kwargs [ 'dry_run' ] :
346355 lines = collections .deque (maxlen = int (os .environ .get ('MAX_LOG_LINES' , 50 )))
347356 process = Popen (run_command , shell = True , stdout = PIPE , stderr = STDOUT )
348357 with process .stdout :
349358 for line in iter (process .stdout .readline , b'' ):
350359 line = line .decode ('utf-8' )
351360 lines .append (line )
352- yield ['\n ' .join (lines )] + Runtime .plot (run_command )
361+ yield ['\n ' .join (lines )] + Runtime .plot (run_command ) + [run_command ]
362+ else :
363+ yield ['Current is dryrun mode, you can only view the training cmd, please '
364+ 'duplicate this space to do training.' ] + [None ] * len (Runtime .sft_plot ) + [run_command ]
353365
354366 @classmethod
355367 def train_local (cls , * args ):
0 commit comments