2014-10-28 34 views
6

Tôi đang cố gắng chạy sklearn.decomposition.TruncatedSVD() trên 2 máy tính khác nhau và hiểu sự khác biệt về hiệu suất.sự khác biệt về hiệu suất gumpy giữa Linux và Windows

máy tính 1 (Windows 7, máy tính vật lý)

OS Name Microsoft Windows 7 Professional 
System Type x64-based PC 
Processor Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz, 3401 Mhz, 4 Core(s), 
8 Logical Installed Physical Memory (RAM) 8.00 GB 
Total Physical Memory 7.89 GB 

máy tính 2 (Debian, trên amazon cloud)

Architecture:   x86_64 
CPU op-mode(s):  32-bit, 64-bit 
Byte Order:   Little Endian 
CPU(s):    8 

width: 64 bits 
capabilities: ldt16 vsyscall32 
*-core 
    description: Motherboard 
    physical id: 0 
*-memory 
    description: System memory 
    physical id: 0 
    size: 29GiB 
*-cpu 
    product: Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz 
    vendor: Intel Corp. 
    physical id: 1 
    bus info: [email protected] 
    width: 64 bits 

máy tính 3 (Windows 2008R2, trên amazon đám mây)

OS Name Microsoft Windows Server 2008 R2 Datacenter 
Version 6.1.7601 Service Pack 1 Build 7601 
System Type x64-based PC 
Processor Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz, 2500 Mhz, 
4 Core(s), 8 Logical Processor(s) 
Installed Physical Memory (RAM) 30.0 GB 

Cả hai máy tính đang chạy với Python 3.2 và sklearn giống hệt nhau, numpy, phiên bản scipy

Tôi chạy cProfile như sau:

print(vectors.shape) 
>>> (7500, 2042) 

_decomp = TruncatedSVD(n_components=680, random_state=1) 
global _o 
_o = _decomp 
cProfile.runctx('_o.fit_transform(vectors)', globals(), locals(), sort=1) 

máy tính 1 đầu ra

>>> 833 function calls in 1.710 seconds 
Ordered by: internal time 

ncalls tottime percall cumtime percall filename:lineno(function) 
    1 0.767 0.767 0.782 0.782 decomp_svd.py:15(svd) 
    1 0.249 0.249 0.249 0.249 {method 'enable' of '_lsprof.Profiler' objects} 
    1 0.183 0.183 0.183 0.183 {method 'normal' of 'mtrand.RandomState' objects} 
    6 0.174 0.029 0.174 0.029 {built-in method csr_matvecs} 
    6 0.123 0.021 0.123 0.021 {built-in method csc_matvecs} 
    2 0.110 0.055 0.110 0.055 decomp_qr.py:14(safecall) 
    1 0.035 0.035 0.035 0.035 {built-in method dot} 
    1 0.020 0.020 0.589 0.589 extmath.py:185(randomized_range_finder) 
    2 0.018 0.009 0.019 0.010 function_base.py:532(asarray_chkfinite) 
    24 0.014 0.001 0.014 0.001 {method 'ravel' of 'numpy.ndarray' objects} 
    1 0.007 0.007 0.009 0.009 twodim_base.py:427(triu) 
    1 0.004 0.004 1.710 1.710 extmath.py:232(randomized_svd) 

Máy tính 2 đầu ra

>>> 858 function calls in 40.145 seconds 
Ordered by: internal time 
ncalls tottime percall cumtime percall filename:lineno(function) 
    2 32.116 16.058 32.116 16.058 {built-in method dot} 
    1 6.148 6.148 6.156 6.156 decomp_svd.py:15(svd) 
    2 0.561 0.281 0.561 0.281 decomp_qr.py:14(safecall) 
    6 0.561 0.093 0.561 0.093 {built-in method csr_matvecs} 
    1 0.337 0.337 0.337 0.337 {method 'normal' of 'mtrand.RandomState' objects} 
    6 0.202 0.034 0.202 0.034 {built-in method csc_matvecs} 
    1 0.052 0.052 1.633 1.633 extmath.py:183(randomized_range_finder) 
    1 0.045 0.045 0.054 0.054 _methods.py:73(_var) 
    1 0.023 0.023 0.023 0.023 {method 'argmax' of 'numpy.ndarray' objects} 
    1 0.023 0.023 0.046 0.046 extmath.py:531(svd_flip) 
    1 0.016 0.016 40.145 40.145 <string>:1(<module>) 
    24 0.011 0.000 0.011 0.000 {method 'ravel' of 'numpy.ndarray' objects} 
    6 0.009 0.002 0.009 0.002 {method 'reduce' of 'numpy.ufunc' objects} 
    2 0.008 0.004 0.009 0.004 function_base.py:532(asarray_chkfinite) 

máy tính 3 đầu ra

>>>   858 function calls in 2.223 seconds 
Ordered by: internal time 
ncalls tottime percall cumtime percall filename:lineno(function) 
    1 0.956 0.956 0.972 0.972 decomp_svd.py:15(svd) 
    2 0.306 0.153 0.306 0.153 {built-in method dot} 
    1 0.274 0.274 0.274 0.274 {method 'normal' of 'mtrand.RandomState' objects} 
    6 0.205 0.034 0.205 0.034 {built-in method csr_matvecs} 
    6 0.151 0.025 0.151 0.025 {built-in method csc_matvecs} 
    2 0.133 0.067 0.133 0.067 decomp_qr.py:14(safecall) 
    1 0.032 0.032 0.043 0.043 _methods.py:73(_var) 
    1 0.030 0.030 0.030 0.030 {method 'argmax' of 'numpy.ndarray' objects} 
    24 0.026 0.001 0.026 0.001 {method 'ravel' of 'numpy.ndarray' objects} 
    2 0.019 0.010 0.020 0.010 function_base.py:532(asarray_chkfinite) 
    1 0.019 0.019 0.773 0.773 extmath.py:183(randomized_range_finder) 
    1 0.019 0.019 0.049 0.049 extmath.py:531(svd_flip) 

Thông báo các {built-in phương pháp chấm} chênh lệch từ 0.035s/cuộc gọi đến 16.058s/cuộc gọi, 450 lần chậm hơn !!

------+---------+---------+---------+---------+--------------------------------------- 
ncalls| tottime | percall | cumtime | percall | filename:lineno(function) HARDWARE 
------+---------+---------+---------+---------+--------------------------------------- 
1  | 0.035 | 0.035 | 0.035 | 0.035 | {built-in method dot}  Computer 1 
2  | 32.116 | 16.058 | 32.116 | 16.058 | {built-in method dot}  Computer 2 
2  | 0.306 | 0.153 | 0.306 | 0.153 | {built-in method dot}  Computer 3 

Tôi hiểu rằng cần có sự khác biệt về hiệu suất, nhưng tôi có nên cao không?

Có cách nào để tôi có thể gỡ rối thêm vấn đề về hiệu suất này không?

EDIT

tôi đã thử nghiệm một máy tính mới, máy tính 3 mà HW của nó cũng tương tự như máy tính 2 và với hệ điều hành khác nhau

Kết quả là 0.153s/cuộc gọi cho {phương pháp tích hợp dot} vẫn nhanh hơn 100 lần so với Linux !!

EDIT 2

máy tính 1 NumPy cấu hình

>>> np.__config__.show() 
lapack_opt_info: 
    libraries = ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'libiomp5md', 'libifportmd', 'mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'libiomp5md', 'libifportmd'] 
    library_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/lib/intel64'] 
    define_macros = [('SCIPY_MKL_H', None)] 
    include_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/include'] 
blas_opt_info: 
    libraries = ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'libiomp5md', 'libifportmd'] 
    library_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/lib/intel64'] 
    define_macros = [('SCIPY_MKL_H', None)] 
    include_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/include'] 
openblas_info: 
    NOT AVAILABLE 
lapack_mkl_info: 
    libraries = ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'libiomp5md', 'libifportmd', 'mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'libiomp5md', 'libifportmd'] 
    library_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/lib/intel64'] 
    define_macros = [('SCIPY_MKL_H', None)] 
    include_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/include'] 
blas_mkl_info: 
    libraries = ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'libiomp5md', 'libifportmd'] 
    library_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/lib/intel64'] 
    define_macros = [('SCIPY_MKL_H', None)] 
    include_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/include'] 
mkl_info: 
    libraries = ['mkl_lapack95_lp64', 'mkl_blas95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'libiomp5md', 'libifportmd'] 
    library_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/lib/intel64'] 
    define_macros = [('SCIPY_MKL_H', None)] 
    include_dirs = ['C:/Program Files (x86)/Intel/Composer XE/mkl/include'] 

máy tính 2 NumPy cấu hình

>>> np.__config__.show() 
lapack_info: 
    NOT AVAILABLE 
lapack_opt_info: 
    NOT AVAILABLE 
blas_info: 
    libraries = ['blas'] 
    library_dirs = ['/usr/lib'] 
    language = f77 
atlas_threads_info: 
    NOT AVAILABLE 
atlas_blas_info: 
    NOT AVAILABLE 
lapack_src_info: 
    NOT AVAILABLE 
openblas_info: 
    NOT AVAILABLE 
atlas_blas_threads_info: 
    NOT AVAILABLE 
blas_mkl_info: 
    NOT AVAILABLE 
blas_opt_info: 
    libraries = ['blas'] 
    library_dirs = ['/usr/lib'] 
    language = f77 
    define_macros = [('NO_ATLAS_INFO', 1)] 
atlas_info: 
    NOT AVAILABLE 
lapack_mkl_info: 
    NOT AVAILABLE 
mkl_info: 
    NOT AVAILABLE 
+0

Cũng bao gồm đầu ra của 'python --version' từ mỗi nút. –

+2

Cũng so sánh 'python -c 'nhập khẩu numpy như np; np .__ config __. show() ''. –

+4

Làm thế nào bạn cài đặt phần mềm không? BLAS nào đang sử dụng?Nếu các cửa sổ hộp sử dụng MKL và Linux sử dụng BLAS mặc định, có thể sẽ giải thích rất nhiều. ('' Np .__ config __. Show() '' đưa ra thông tin này) –

Trả lời

4

{built-in method dot} là chức năng np.dot, là một trình bao bọc NumPy xung quanh các quy trình CBLAS cho ma trận ma trận, ma trận-vector và vector-vector nhân. Máy Windows của bạn sử dụng phiên bản Intel MKL được điều chỉnh nhiều của CBLAS. Máy Linux đang sử dụng cài đặt tham chiếu cũ chậm.

Nếu bạn cài đặt ATLAS hoặc OpenBLAS (cả hai đều có sẵn thông qua trình quản lý gói Linux) hoặc, trên thực tế, Intel MKL, bạn có thể thấy tăng tốc lớn. Hãy thử sudo apt-get install libatlas-dev, kiểm tra lại cấu hình NumPy để xem nó có nhận được ATLAS hay không và đo lại.

Khi bạn đã quyết định đúng thư viện CBLAS, bạn có thể muốn biên dịch lại scikit-learn. Hầu hết nó chỉ sử dụng NumPy cho nhu cầu đại số tuyến tính của nó, nhưng một số thuật toán (đặc biệt là k-means) sử dụng CBLAS trực tiếp.

Hệ điều hành không liên quan gì đến điều này.

1

Noti ce {built-in method dot} chênh lệch từ 0,035s/cuộc gọi đến 16,058s/cuộc gọi, chậm hơn 450 lần !!

Tốc độ đồng hồ và tỷ lệ truy cập bộ nhớ cache là hai yếu tố quan trọng cần xem xét. Xeon E5-2670 có bộ nhớ đệm nhiều hơn so với Core i7-3770. Và i7-3770 có tốc độ đồng hồ đỉnh cao hơn với chế độ turbo. Trong khi Xeon của bạn có bộ nhớ cache lớn trong phần cứng, trên EC2, bạn có thể chia sẻ bộ nhớ cache đó hiệu quả với các khách hàng khác.

Có cách nào để tôi có thể gỡ rối thêm vấn đề về hiệu suất này không?

Vâng, bạn có các phép đo khác nhau (đầu ra) và nhiều khác biệt về đầu vào (OS và phần cứng). Với các đầu vào khác nhau, các đầu ra khác nhau này có thể được mong đợi.

Bộ đếm hiệu suất CPU sẽ tách biệt hiệu quả của thuật toán hiệu suất của bạn trên các hệ thống khác nhau. Xeon có bộ đếm hiệu suất phong phú hơn, nhưng tất cả chúng phải có CPU_CLK_UNHALTEDLLC_MISSES. Những công việc này bằng cách ánh xạ con trỏ chỉ dẫn đến các sự kiện như mã đang được thực hiện hoặc bộ đệm ẩn. Vì vậy, bạn có thể thấy những phần nào của mã là CPU và cache bị ràng buộc. Kể từ khi tốc độ đồng hồ và kích thước bộ nhớ cache khác nhau giữa các mục tiêu của bạn, bạn có thể thấy rằng một là bộ nhớ cache bị ràng buộc và khác là CPU bị ràng buộc.

Linux có công cụ được gọi là perf (đôi khi perf_events). Xem thêm http://www.brendangregg.com/perf.html

Trên Linux và Windows, bạn cũng có thể sử dụng Intel VTune.

+0

Tôi đã chỉnh sửa câu hỏi của mình, thêm máy tính 3 để loại bỏ sự cố HW khác nhau –

Các vấn đề liên quan