Python xóa bộ đệm đầu vào

Xem các phiên từ Hội nghị chuyên đề WiML về các mô hình khuếch tán với KerasCV, ML trên thiết bị, v.v. Xem theo yêu cầu

  • TenorFlow
  • Học hỏi
  • Lõi TensorFlow
  • Hướng dẫn

Hiệu suất tốt hơn với tf. API dữ liệu Sắp xếp ngăn nắp với các bộ sưu tập Lưu và phân loại nội dung dựa trên sở thích của bạn

Xem trên TensorFlow. org
Chạy trong Google Colab
Xem nguồn trên GitHub
Tải xuống sổ ghi chép

Tổng quan

GPU và TPU có thể giảm triệt để thời gian cần thiết để thực hiện một bước đào tạo. Đạt được hiệu suất cao nhất yêu cầu một quy trình đầu vào hiệu quả cung cấp dữ liệu cho bước tiếp theo trước khi bước hiện tại kết thúc. API

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
8 giúp xây dựng các đường dẫn đầu vào linh hoạt và hiệu quả. Tài liệu này trình bày cách sử dụng API
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
8 để xây dựng các quy trình đầu vào TensorFlow hiệu suất cao

Trước khi bạn tiếp tục, hãy xem hướng dẫn Xây dựng quy trình đầu vào TensorFlow để tìm hiểu cách sử dụng API

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
8

Tài nguyên

  • Xây dựng đường ống đầu vào TensorFlow
  • benchmark[ArtificialDataset[]]
    
    1 API
  • Phân tích hiệu suất của
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    8 với TF Profiler

Cài đặt

import tensorflow as tf

import time
2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.

Xuyên suốt hướng dẫn này, bạn sẽ lặp lại một tập dữ liệu và đo lường hiệu suất. Việc tạo ra các điểm chuẩn hiệu suất có thể lặp lại có thể khó khăn. Các yếu tố khác nhau ảnh hưởng đến khả năng tái sản xuất bao gồm

  • Tải CPU hiện tại
  • Lưu lượng mạng
  • Các cơ chế phức tạp, chẳng hạn như bộ đệm

Để có được điểm chuẩn có thể lặp lại, bạn sẽ xây dựng một ví dụ nhân tạo

tập dữ liệu

Bắt đầu với việc định nghĩa một lớp kế thừa từ

benchmark[ArtificialDataset[]]
1 có tên là
benchmark[ArtificialDataset[]]
4. tập dữ liệu này

  • Tạo
    benchmark[ArtificialDataset[]]
    
    5 mẫu [mặc định là 3]
  • Ngủ một thời gian trước mục đầu tiên để mô phỏng mở tệp
  • Ngủ một thời gian trước khi tạo từng mục để mô phỏng đọc dữ liệu từ một tệp
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
0

Bộ dữ liệu này tương tự như bộ dữ liệu

benchmark[ArtificialDataset[]]
6, thêm độ trễ cố định ở đầu và giữa mỗi mẫu

Vòng lặp đào tạo

Tiếp theo, hãy viết một vòng lặp đào tạo giả đo thời gian cần thiết để lặp lại một tập dữ liệu. Thời gian đào tạo được mô phỏng

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]

Tối ưu hóa hiệu suất

Để thể hiện cách tối ưu hóa hiệu suất, bạn sẽ cải thiện hiệu suất của

benchmark[ArtificialDataset[]]
4

Cách tiếp cận ngây thơ

Bắt đầu với một quy trình ngây thơ không sử dụng thủ thuật nào, lặp lại nguyên trạng tập dữ liệu

benchmark[ArtificialDataset[]]
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
5

Dưới mui xe, đây là cách thời gian thực hiện của bạn đã được sử dụng

Cốt truyện cho thấy rằng việc thực hiện một bước đào tạo liên quan đến

  • Mở một tệp nếu nó chưa được mở
  • Tìm nạp một mục nhập dữ liệu từ tệp
  • Sử dụng dữ liệu để huấn luyện

Tuy nhiên, trong một triển khai đồng bộ ngây thơ như ở đây, trong khi đường ống của bạn đang tìm nạp dữ liệu, mô hình của bạn sẽ không hoạt động. Ngược lại, trong khi mô hình của bạn đang đào tạo, đường dẫn đầu vào không hoạt động. Do đó, thời gian của bước đào tạo là tổng của thời gian mở, đọc và đào tạo

Các phần tiếp theo được xây dựng trên quy trình đầu vào này, minh họa các phương pháp hay nhất để thiết kế quy trình đầu vào TensorFlow hoạt động hiệu quả

tìm nạp trước

Tìm nạp trước chồng chéo quá trình tiền xử lý và thực thi mô hình của một bước đào tạo. Trong khi mô hình đang thực hiện bước đào tạo

benchmark[ArtificialDataset[]]
8, đường dẫn đầu vào đang đọc dữ liệu cho bước
benchmark[ArtificialDataset[]]
9. Làm như vậy sẽ giảm thời gian bước xuống mức tối đa [trái ngược với tổng] của quá trình đào tạo và thời gian trích xuất dữ liệu

API

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
8 cung cấp phép chuyển đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
51. Nó có thể được sử dụng để tách thời gian khi dữ liệu được tạo ra từ thời điểm dữ liệu được sử dụng. Cụ thể, quá trình chuyển đổi sử dụng luồng nền và bộ đệm bên trong để tìm nạp trước các phần tử từ tập dữ liệu đầu vào trước thời điểm chúng được yêu cầu. Số lượng phần tử để tìm nạp trước phải bằng [hoặc có thể lớn hơn] số lượng lô được sử dụng bởi một bước đào tạo. Bạn có thể điều chỉnh giá trị này theo cách thủ công hoặc đặt giá trị đó thành
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
52, điều này sẽ nhắc bộ thực thi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
8 tự động điều chỉnh giá trị trong thời gian chạy

Lưu ý rằng chuyển đổi tìm nạp trước mang lại lợi ích bất cứ khi nào có cơ hội chồng chéo công việc của "nhà sản xuất" với công việc của "người tiêu dùng". "

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
2____23

Bây giờ, khi biểu đồ thời gian thực hiện dữ liệu hiển thị, trong khi bước đào tạo đang chạy cho mẫu 0, đường dẫn đầu vào đang đọc dữ liệu cho mẫu 1, v.v.

Khai thác dữ liệu song song

Trong cài đặt trong thế giới thực, dữ liệu đầu vào có thể được lưu trữ từ xa [ví dụ: trên Google Cloud Storage hoặc HDFS]. Đường dẫn tập dữ liệu hoạt động tốt khi đọc dữ liệu cục bộ có thể bị tắc nghẽn trên I/O khi đọc dữ liệu từ xa do những khác biệt sau giữa lưu trữ cục bộ và lưu trữ từ xa

  • Thời gian đến byte đầu tiên. Việc đọc byte đầu tiên của tệp từ bộ nhớ từ xa có thể mất nhiều thời gian hơn so với từ bộ nhớ cục bộ
  • Đọc thông lượng. Mặc dù bộ nhớ từ xa thường cung cấp băng thông tổng hợp lớn, nhưng việc đọc một tệp có thể chỉ sử dụng được một phần nhỏ băng thông này

Ngoài ra, một khi các byte thô được tải vào bộ nhớ, cũng có thể cần phải giải tuần tự hóa và/hoặc giải mã dữ liệu [e. g. protobuf], yêu cầu tính toán bổ sung. Chi phí chung này xuất hiện bất kể dữ liệu được lưu trữ cục bộ hay từ xa, nhưng có thể tồi tệ hơn trong trường hợp từ xa nếu dữ liệu không được tìm nạp trước một cách hiệu quả

Để giảm thiểu tác động của các chi phí trích xuất dữ liệu khác nhau, phép biến đổi

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
54 có thể được sử dụng để song song hóa bước tải dữ liệu, xen kẽ nội dung của các bộ dữ liệu khác [chẳng hạn như trình đọc tệp dữ liệu]. Số lượng bộ dữ liệu trùng lặp có thể được chỉ định bởi đối số
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
55, trong khi mức độ song song có thể được chỉ định bởi đối số
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
56. Tương tự như phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
57, phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
58 hỗ trợ
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
52, sẽ ủy thác quyết định về mức độ song song sẽ sử dụng cho thời gian chạy
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
8

xen kẽ tuần tự

Các đối số mặc định của phép biến đổi

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
54 làm cho nó xen kẽ các mẫu đơn lẻ từ hai bộ dữ liệu theo trình tự

benchmark[ArtificialDataset[]]
2____33

Biểu đồ thời gian thực thi dữ liệu này cho phép thể hiện hành vi của phép biến đổi

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
58, tìm nạp các mẫu thay thế từ hai bộ dữ liệu có sẵn. Tuy nhiên, không có cải tiến hiệu suất nào liên quan ở đây

xen kẽ song song

Bây giờ, hãy sử dụng đối số

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
56 của phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
58. Điều này tải song song nhiều bộ dữ liệu, giảm thời gian chờ mở tệp

2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
0
2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
1

Lần này, như biểu đồ thời gian thực thi dữ liệu cho thấy, việc đọc hai bộ dữ liệu được thực hiện song song, giúp giảm thời gian xử lý dữ liệu chung

Chuyển đổi dữ liệu song song

Khi chuẩn bị dữ liệu, các yếu tố đầu vào có thể cần được xử lý trước. Để đạt được điều này, API

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
8 cung cấp phép chuyển đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
26, áp dụng hàm do người dùng xác định cho từng thành phần của tập dữ liệu đầu vào. Do các phần tử đầu vào độc lập với nhau nên quá trình tiền xử lý có thể được thực hiện song song trên nhiều lõi CPU. Để thực hiện điều này, tương tự như các phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
57 và
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
58, phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
29 cung cấp đối số
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
56 để chỉ định mức độ song song

Việc chọn giá trị tốt nhất cho đối số

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
56 tùy thuộc vào phần cứng của bạn, đặc điểm của dữ liệu đào tạo [chẳng hạn như kích thước và hình dạng của nó], chi phí của chức năng bản đồ và quá trình xử lý khác đang diễn ra trên CPU cùng lúc. Một heuristic đơn giản là sử dụng số lõi CPU có sẵn. Tuy nhiên, đối với chuyển đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
57 và
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
58, chuyển đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
29 hỗ trợ
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
52 sẽ ủy quyền quyết định về mức độ song song sẽ sử dụng cho thời gian chạy
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
8

2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
2

ánh xạ tuần tự

Bắt đầu bằng cách sử dụng phép biến đổi

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
29 không song song làm ví dụ cơ bản

2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
3
2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
4

Đối với cách tiếp cận ngây thơ, ở đây, như cốt truyện cho thấy, thời gian dành cho các bước mở, đọc, tiền xử lý [ánh xạ] và đào tạo cộng lại cho một lần lặp lại

ánh xạ song song

Bây giờ, hãy sử dụng cùng chức năng tiền xử lý nhưng áp dụng song song trên nhiều mẫu

2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
5
2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
6

Như biểu đồ dữ liệu minh họa, các bước tiền xử lý chồng lên nhau, giảm tổng thời gian cho một lần lặp

Bộ nhớ đệm

Phép biến đổi

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
38 có thể lưu vào bộ nhớ cache một tập dữ liệu, trong bộ nhớ hoặc trên bộ nhớ cục bộ. Điều này sẽ giúp một số thao tác [như mở tệp và đọc dữ liệu] không bị thực thi trong mỗi kỷ nguyên.

2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
7
2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
8

Ở đây, biểu đồ thời gian thực thi dữ liệu cho thấy rằng khi bạn lưu trữ một tập dữ liệu, các phép biến đổi trước biến đổi

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
39 [như mở tệp và đọc dữ liệu] chỉ được thực hiện trong kỷ nguyên đầu tiên. Các kỷ nguyên tiếp theo sẽ sử dụng lại dữ liệu được lưu trong bộ nhớ cache của phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
39

Nếu hàm do người dùng xác định được chuyển vào phép biến đổi

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
29 tốn kém, hãy áp dụng phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
39 sau phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
29 miễn là tập dữ liệu kết quả vẫn có thể vừa với bộ nhớ hoặc bộ nhớ cục bộ. Nếu hàm do người dùng xác định làm tăng dung lượng cần thiết để lưu trữ tập dữ liệu vượt quá dung lượng bộ đệm, hãy áp dụng hàm đó sau khi chuyển đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
39 hoặc xem xét xử lý trước dữ liệu của bạn trước công việc đào tạo để giảm mức sử dụng tài nguyên

Vector hóa ánh xạ

Việc gọi một hàm do người dùng xác định được chuyển vào phép biến đổi

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
29 có chi phí liên quan đến việc lên lịch và thực thi hàm do người dùng xác định. Vector hóa hàm do người dùng xác định [nghĩa là để hàm này hoạt động trên một loạt đầu vào cùng một lúc] và áp dụng phép biến đổi
benchmark[ArtificialDataset[]]
26 trước phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
29

Để minh họa cho phương pháp hay này, tập dữ liệu nhân tạo của bạn không phù hợp. Độ trễ lập lịch là khoảng 10 micro giây [10e-6 giây], ít hơn nhiều so với hàng chục mili giây được sử dụng trong

benchmark[ArtificialDataset[]]
4 và do đó tác động của nó khó có thể thấy được

Đối với ví dụ này, hãy sử dụng hàm cơ sở

benchmark[ArtificialDataset[]]
6 và đơn giản hóa vòng lặp đào tạo về dạng đơn giản nhất

2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
9

ánh xạ vô hướng

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
00
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
01

Biểu đồ trên minh họa những gì đang diễn ra [với ít mẫu hơn] bằng phương pháp ánh xạ vô hướng. Nó cho thấy rằng chức năng ánh xạ được áp dụng cho từng mẫu. Mặc dù chức năng này rất nhanh, nhưng nó có một số chi phí hoạt động ảnh hưởng đến hiệu suất thời gian

Ánh xạ vector hóa

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
02
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
03

Lần này, hàm ánh xạ được gọi một lần và áp dụng cho một lô mẫu. Như biểu đồ thời gian thực hiện dữ liệu cho thấy, trong khi chức năng có thể mất nhiều thời gian hơn để thực thi, thì chi phí hoạt động chỉ xuất hiện một lần, giúp cải thiện hiệu suất thời gian tổng thể

Giảm dung lượng bộ nhớ

Một số phép biến đổi, bao gồm

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
58,
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
57 và
benchmark[ArtificialDataset[]]
32, duy trì bộ đệm bên trong của các phần tử. Nếu hàm do người dùng xác định được chuyển vào phép biến đổi
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
29 sẽ thay đổi kích thước của các phần tử, thì thứ tự của phép biến đổi bản đồ và các phép biến đổi mà các phần tử đệm ảnh hưởng đến việc sử dụng bộ nhớ. Nói chung, hãy chọn thứ tự dẫn đến dung lượng bộ nhớ thấp hơn, trừ khi thứ tự khác là mong muốn cho hiệu suất

Bộ nhớ đệm tính toán một phần

Bạn nên lưu tập dữ liệu vào bộ đệm sau khi chuyển đổi

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
29 trừ khi việc chuyển đổi này làm cho dữ liệu quá lớn để vừa với bộ nhớ. Có thể đạt được sự đánh đổi nếu chức năng được ánh xạ của bạn có thể được chia thành hai phần. một phần tốn thời gian và một phần tốn bộ nhớ. Trong trường hợp này, bạn có thể xâu chuỗi các phép biến đổi của mình như bên dưới

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
04

Bằng cách này, phần tốn thời gian chỉ được thực hiện trong kỷ nguyên đầu tiên và bạn tránh sử dụng quá nhiều dung lượng bộ đệm

Tóm tắt thực tiễn tốt nhất

Dưới đây là tóm tắt các phương pháp hay nhất để thiết kế đường ống đầu vào TensorFlow hiệu quả

  • Sử dụng phép biến đổi
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    57 để chồng chéo công việc của nhà sản xuất và người tiêu dùng
  • Song song hóa quá trình chuyển đổi đọc dữ liệu bằng cách sử dụng phép biến đổi
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    58
  • Song song hóa phép biến đổi
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    29 bằng cách đặt đối số
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    56
  • Sử dụng biến đổi
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    39 để lưu trữ dữ liệu vào bộ nhớ trong kỷ nguyên đầu tiên
  • Vectorize các hàm do người dùng định nghĩa được chuyển vào phép biến đổi
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    29
  • Giảm mức sử dụng bộ nhớ khi áp dụng các phép biến đổi
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    58,
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    57 và
    benchmark[ArtificialDataset[]]
    
    32

Tái tạo các số liệu

Ghi chú. Phần còn lại của sổ ghi chép này là về cách tái tạo các số liệu trên. Vui lòng chơi với mã này, nhưng hiểu nó không phải là một phần thiết yếu của hướng dẫn này.

Để tìm hiểu sâu hơn về sự hiểu biết về API

benchmark[ArtificialDataset[]]
1, bạn có thể chơi với các quy trình của riêng mình. Dưới đây là mã được sử dụng để vẽ các hình ảnh từ hướng dẫn này. Nó có thể là một điểm khởi đầu tốt, chỉ ra một số cách giải quyết cho những khó khăn phổ biến như

  • Khả năng lặp lại thời gian thực hiện
  • Chức năng ánh xạ háo hức thực hiện
  • Biến đổi
    def benchmark[dataset, num_epochs=2]:
        start_time = time.perf_counter[]
        for epoch_num in range[num_epochs]:
            for sample in dataset:
                # Performing a training step
                time.sleep[0.01]
        print["Execution time:", time.perf_counter[] - start_time]
    
    58 có thể gọi được
def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
05

tập dữ liệu

Tương tự như

benchmark[ArtificialDataset[]]
4, bạn có thể tạo bộ dữ liệu trả về thời gian dành cho mỗi bước

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
06

Bộ dữ liệu này cung cấp các mẫu có hình dạng

2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
07 và loại
2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
08. Mỗi mẫu là

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
07

Ở đâu

  • 2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
    
    09 và
    2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
    
    10 là số nhận dạng bước
  • 2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
    
    11 là dấu thời gian khi bước tương ứng bắt đầu
  • 2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
    
    12 là thời gian dành cho bước tương ứng
  • 2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
    
    13 là chỉ mục cá thể
  • 2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
    2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
    
    14 là chỉ số kỷ nguyên [số lần tập dữ liệu được lặp lại]
  • benchmark[ArtificialDataset[]]
    
    8 là chỉ số mẫu

Vòng lặp lặp

Làm cho vòng lặp phức tạp hơn một chút để tổng hợp tất cả các thời gian. Điều này sẽ chỉ hoạt động với các mẫu tạo bộ dữ liệu như chi tiết ở trên

def benchmark[dataset, num_epochs=2]:
    start_time = time.perf_counter[]
    for epoch_num in range[num_epochs]:
        for sample in dataset:
            # Performing a training step
            time.sleep[0.01]
    print["Execution time:", time.perf_counter[] - start_time]
08

phương pháp vẽ đồ thị

Cuối cùng, hãy xác định một hàm có thể vẽ biểu đồ dòng thời gian với các giá trị được trả về bởi hàm

2022-12-14 04:18:49.223536: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory
2022-12-14 04:18:49.223651: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
16

Chủ Đề