Spaces:
Running
Running
Update visualizer.
Browse filesFiles changed (2)
- main.py+1-1
- src/visualizer.py+67-44
123456from src.execution_model import ScheduleConfig, ScheduleExecutorfrom src.strategies import generate_1f1b_interleave_schedule, generate_1f1b_schedulefrom src.visualizer import visualize_pipeline_parallelism_dash, save_pipeline_visualization_plotlyimport hydrafrom omegaconf import DictConfig, OmegaConf123456from src.execution_model import ScheduleConfig, ScheduleExecutorfrom src.strategies import generate_1f1b_interleave_schedule, generate_1f1b_schedulefrom src.visualizer import visualize_pipeline_parallelism_dashimport hydrafrom omegaconf import DictConfig, OmegaConf
54 unmodified lines55565758596061626364656667686970717273747576777886 unmodified lines16516616716816917017117217317434 unmodified lines20921021121221321421521621721821922022122262 unmodified lines28528628728828929029134 unmodified lines32632732832933033133233333433533633733833934034134234334434534634734854 unmodified linesempty_color = "whitesmoke"# Colors for task typesdef get_color(op_type: str, stage_id: int):# Base colorsforward_base_color = "royalblue"backward_base_color = "lightgreen" # Changed from sandybrown to match your visualizationvirtual_stage = stage_id // num_devicesif op_type == "forward":if virtual_stage == 0:return forward_base_colorelse:# Lighter shade for virtual_stage > 0return "lightskyblue"elif op_type == "backward":if virtual_stage == 0:return backward_base_colorelse:# Lighter shade for virtual_stage > 0return "lightseagreen"else:raise ValueError(f"Invalid operation type: {op_type}")86 unmodified linesprogress_bar.update(1)# Add custom legendlegend_items = [dict(name="Forward", color=get_color("forward", 0)),dict(name="Backward", color=get_color("backward", 0)),]for i, item in enumerate(legend_items):fig.add_trace(go.Scatter(34 unmodified linesfont=dict(size=20)),legend=dict(orientation="h",yanchor="top",y=-0.1, # Position below the plotxanchor="center",x=0.5),width=1600,height=400, # Reduce height to make the visualization more compactbargap=0,bargroupgap=0,)62 unmodified linesdef load_graph(_):# Create the figure when the app loadsreturn create_pipeline_figure(schedule_data, show_progress=True)@app.callback(Output("download-image", "data"),Input("btn-download", "n_clicks"),34 unmodified linesapp = create_dash_app(schedule)print(f"Starting Dash app on http://localhost:{port}/")app.run_server(debug=debug, port=port)def save_pipeline_visualization_plotly(schedule: Schedule,output_file: str = "pipeline_visualization_plotly.png",):"""Save a static image of the pipeline schedule visualization.Args:schedule: Schedule object to visualizeoutput_file: Path to save the image to"""schedule_data = convert_schedule_to_visualization_format(schedule)fig = create_pipeline_figure(schedule_data, show_progress=True)print(f"Saving visualization to {output_file}...")fig.write_image(output_file, width=1600, height=400, scale=2)print(f"Visualization saved to {output_file}")54 unmodified lines55565758596061626364656667686970717273747576777879808182838485868788899091929394959686 unmodified lines18318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321434 unmodified lines24925025125225325425525625725825926026126226326426562 unmodified lines32832933033133233333434 unmodified lines36937037154 unmodified linesempty_color = "whitesmoke"# Colors for task typesdef get_color(op_type: str, stage_id: int):# Color palettes for different virtual stagesforward_colors = ["royalblue", # Stage 0"lightskyblue", # Stage 1"cornflowerblue", # Stage 2"steelblue", # Stage 3"dodgerblue", # Stage 4"deepskyblue", # Stage 5"mediumblue", # Stage 6"mediumslateblue",# Stage 7"slateblue", # Stage 8"darkslateblue" # Stage 9]backward_colors = ["lightgreen", # Stage 0"mediumseagreen", # Stage 1"seagreen", # Stage 2"lightseagreen", # Stage 3"mediumaquamarine", # Stage 4"mediumspringgreen", # Stage 5"springgreen", # Stage 6"palegreen", # Stage 7"limegreen", # Stage 8"forestgreen" # Stage 9]virtual_stage = stage_id // num_devices# If virtual_stage is beyond our color list, cycle through the colorscolor_index = virtual_stage % len(forward_colors)if op_type == "forward":return forward_colors[color_index]elif op_type == "backward":return backward_colors[color_index]else:raise ValueError(f"Invalid operation type: {op_type}")86 unmodified linesprogress_bar.update(1)# Add custom legendlegend_items = []# Find the maximum virtual stage in the datamax_virtual_stage = 0for device in schedule_data:for task in schedule_data[device]:virtual_stage = task["stage"] // num_devicesmax_virtual_stage = max(max_virtual_stage, virtual_stage)# Add forward and backward items for each virtual stagefor vs in range(max_virtual_stage + 1):legend_items.append(dict(name=f"Forward (VS {vs})",color=get_color("forward", vs * num_devices)))legend_items.append(dict(name=f"Backward (VS {vs})",color=get_color("backward", vs * num_devices)))# If no tasks found, add default legend itemsif not legend_items:legend_items = [dict(name="Forward (VS 0)", color=get_color("forward", 0)),dict(name="Backward (VS 0)", color=get_color("backward", 0)),]for i, item in enumerate(legend_items):fig.add_trace(go.Scatter(34 unmodified linesfont=dict(size=20)),legend=dict(orientation="v", # Changed from horizontal to verticalyanchor="top",y=1.02, # Position at the topxanchor="right",x=1.15, # Position to the right of the plottitle=dict(text="<b>Operation Types:</b>"),itemsizing="constant",tracegroupgap=0),width=1800, # Increase width to accommodate the legendheight=400, # Maintain current heightbargap=0,bargroupgap=0,)62 unmodified linesdef load_graph(_):# Create the figure when the app loadsreturn create_pipeline_figure(schedule_data, show_progress=True)@app.callback(Output("download-image", "data"),Input("btn-download", "n_clicks"),34 unmodified linesapp = create_dash_app(schedule)print(f"Starting Dash app on http://localhost:{port}/")app.run_server(debug=debug, port=port)
main.py+1-1
src/visualizer.py+67-44