-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix v2 init issue on Mac #5808
fix v2 init issue on Mac #5808
Conversation
python/paddle/v2/__init__.py
Outdated
# do not support on other platform yet | ||
return False | ||
|
||
def get_logical_processors(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function returns the number of logical processors, other than a list of logical processors, so it should be named either get_num_logical_processor
or num_logical_processor
. Otherwise, we'd lose the most important concept "number".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks, I will use num_logical_processor
instead.
python/paddle/v2/__init__.py
Outdated
'''Get the logical processors number''' | ||
import platform | ||
if platform.system() == "Linux": | ||
processors = os.popen( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, processors
=> num_proc
or num_processors
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
python/paddle/v2/__init__.py
Outdated
return int(processors.read()) | ||
else: | ||
# do not support on other platform yet | ||
return 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function definition (26 lines, from L82 to L108) can be significantly shortened (into 4 lines) while keeping the readability:
def num_logical_processor():
cmds = { "Linux" : "grep \"processor\" /proc/cpuinfo|sort -u|wc -l",
"Darwin" : "sysctl hw.logicalcpu" }
return int(os.popen(cmds.get(platform.system(), "expr 1")).read())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, Thx.
python/paddle/v2/__init__.py
Outdated
for key in args_dict.keys(): | ||
args.append('--%s=%s' % (key, str(args_dict[key]))) | ||
|
||
auto_set_cpu_env(kwargs.get('trainer_count', 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All programs, including auto_set_cpu_env
, were written to do something automatically, so it seems that an accurate name could be set_omp_mkl_env_vars
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will update it later.
python/paddle/v2/__init__.py
Outdated
# do not support on other platform yet | ||
return False | ||
|
||
def get_logical_processors(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks, I will use num_logical_processor
instead.
python/paddle/v2/__init__.py
Outdated
'''Get the logical processors number''' | ||
import platform | ||
if platform.system() == "Linux": | ||
processors = os.popen( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
python/paddle/v2/__init__.py
Outdated
return int(processors.read()) | ||
else: | ||
# do not support on other platform yet | ||
return 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, Thx.
python/paddle/v2/__init__.py
Outdated
for key in args_dict.keys(): | ||
args.append('--%s=%s' % (key, str(args_dict[key]))) | ||
|
||
auto_set_cpu_env(kwargs.get('trainer_count', 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thx.
Have tested on Mac, v2 Python API is fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
fix #5801
hi @jacquesqiao I do not have mac to test, so could u help?
I have already verified it on Linux, and it works.