File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
src/lightning/pytorch/profilers Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 1515
1616import logging
1717import os
18+ import re
1819from abc import ABC , abstractmethod
1920from collections .abc import Generator
2021from contextlib import contextmanager
@@ -81,6 +82,7 @@ def _prepare_filename(
8182 action_name : Optional [str ] = None ,
8283 extension : str = ".txt" ,
8384 split_token : str = "-" , # noqa: S107
85+ sanitize : bool = True ,
8486 ) -> str :
8587 args = []
8688 if self ._stage is not None :
@@ -91,7 +93,15 @@ def _prepare_filename(
9193 args .append (str (self ._local_rank ))
9294 if action_name is not None :
9395 args .append (action_name )
94- return split_token .join (args ) + extension
96+ base = split_token .join (args )
97+ if sanitize :
98+ # Replace a set of path-unsafe characters across platforms with '_'
99+ base = re .sub (r"[\\/:*?\"<>|\n\r\t]" , "_" , base )
100+ base = re .sub (r"_+" , "_" , base )
101+ base = base .strip ()
102+ if not base :
103+ base = "profile"
104+ return base + extension
95105
96106 def _prepare_streams (self ) -> None :
97107 if self ._write_stream is not None :
You can’t perform that action at this time.
0 commit comments