2023-12-09 22:34:33.872992: I tensorflow/core/util/port.cc:113] oneDNN custom operations…
- User
2023-12-09 22:34:33.872992: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable
TF_ENABLE_ONEDNN_OPTS=0. WARNING:tensorflow:From C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.Traceback (most recent call last): File "D:\AI\RunProject.py", line 20, in model = BlipForConditionalGeneration.from_pretrained(model_Main) File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\transformers\modeling_utils.py", line 2975, in from_pretrained raise EnvironmentError( OSError: Error no file named pytorch_model.bin found in directory ./Main but there is a file for TensorFlow weights. Use
from_tf=Trueto load this model from those weights. - Assistant
It seems you are encountering an error while trying to load a pre-trained model using the Hugging Face Transformers library. The error suggests that the function
from_pretrainedis looking for a PyTorch model file namedpytorch_model.binwithin the directory./Main, but it cannot find it. Instead, it has found TensorFlow weights.The solution is as suggested by the error message: you should add the parameter
from_tf=Truewhen you callfrom_pretrainedif you want to load the model from TensorFlow weights.Here's how you can modify your code:
model = BlipForConditionalGeneration.from_pretrained(model_Main, from_tf=True)This tells the method to look for and load the model from TensorFlow weights instead of the default PyTorch weights.
Also, regarding the deprecation warning, TensorFlow is notifying you that the function
tf.losses.sparse_softmax_cross_entropyis deprecated and should be replaced withtf.compat.v1.losses.sparse_softmax_cross_entropy. Deprecation warnings like this advise you that in future versions of TensorFlow, the deprecated function may be removed or no longer supported.To resolve this warning, you should update your code to use the suggested compatible version (or if your code is not directly calling this function, update the library or package that is calling it):
# Replace this (deprecated) tf.losses.sparse_softmax_cross_entropy(labels, logits) # With this (compatible version) tf.compat.v1.losses.sparse_softmax_cross_entropy(labels, logits)If you do not own the code triggering the warning, consider updating the library that does.
Lastly, the message about oneDNN custom operations informs you that oneDNN optimizations are enabled, which might lead to slight differences in numerical results due to floating-point rounding. If you wish to disable these optimizations, you can do so by setting the environment variable as instructed.
Here's how you can set the environment variable in Python before importing TensorFlow:
import os os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' import tensorflow as tfMake sure to set the environment variable at the beginning of your script before importing TensorFlow or any module that initializes TensorFlow.
- User
là sao
- Assistant
Xin lỗi nếu câu trả lời trước của tôi không rõ ràng. Bạn đang gặp lỗi khi cố gắng tải một mô hình đã được đào tạo trước từ thư viện Hugging Face Transformers, mà cụ thể là mô hình
BlipForConditionalGeneration. Mô hình này cần được tải từ một tệp tin PyTorch (có tên làpytorch_model.bin), nhưng trong thư mục của bạn chỉ có trọng số TensorFlow mà thôi.Để giải quyết vấn đề này, bạn cần chỉ định rằng bạn muốn tải mô hình từ trọng số TensorFlow bằng cách thêm tham số
from_tf=Truevào phương thứcfrom_pretrainednhư sau:model = BlipForConditionalGeneration.from_pretrained(model_Main, from_tf=True)Ngoài ra, bạn cũng nhận được cảnh báo về việc một hàm trong TensorFlow đã lỗi thời (deprecated), và bạn nên cập nhật mã của mình để sử dụng phiên bản mới hơn của hàm đó nếu bạn đang trực tiếp gọi nó.
Về thông báo liên quan đến oneDNN, đó chỉ là một thông báo cho bạn biết rằng các tối ưu hóa oneDNN đã được bật, và nếu bạn muốn tắt chúng đi, bạn cần thiết lập một biến môi trường (
TF_ENABLE_ONEDNN_OPTS=0) trước khi chạy mã TensorFlow của mình. - User
ở đâu TF_ENABLE_ONEDNN_OPTS=0
- Assistant
TF_ENABLE_ONEDNN_OPTS=0là một biến môi trường mà bạn cần thiết lập trên hệ thống của bạn để tắt các tùy chọn tối ưu hóa oneDNN trong TensorFlow. Để thiết lập biến môi trường này trong mã Python của bạn, hãy thêm đoạn mã sau trước khi bạn import tensorflow:import os # Set the environment variable os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' # Now you can import TensorFlow import tensorflow as tfNếu bạn đang sử dụng terminal hoặc command line, bạn có thể thiết lập biến môi trường trước khi chạy script Python của mình. Dưới đây là cách làm theo từng hệ điều hành:
Trên Windows (Command Prompt):
set TF_ENABLE_ONEDNN_OPTS=0 python script.pyTrên Windows (PowerShell):
$env:TF_ENABLE_ONEDNN_OPTS="0" python script.pyTrên Linux hoặc macOS:
export TF_ENABLE_ONEDNN_OPTS=0 python script.pyThay
script.pybằng tên file Python chứa mã của bạn. Sau khi thiết lập biến môi trường này, các tùy chọn tối ưu hóa oneDNN sẽ bị tắt khi bạn chạy script Python của mình. - User
Traceback (most recent call last): File "D:\AI\RunProject.py", line 13, in tokenizertrans = MarianTokenizer.from_pretrained(model_trans) File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\transformers\tokenization_utils_base.py", line 1947, in from_pretrained File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\transformers\utils\hub.py", line 430, in cached_file resolved_file = hf_hub_download( File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\huggingface_hub\utils_validators.py", line 110, in _inner_fn validate_repo_id(arg_value) File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\huggingface_hub\utils_validators.py", line 164, in validate_repo_id raise HFValidationError( huggingface_hub.utils.validators.HFValidationError: Repo id must use alphanumeric chars or '-', '', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: '/trans'. PS D:\AI> python .\RunProject.py Traceback (most recent call last): File "D:\AI\RunProject.py", line 13, in tokenizertrans = MarianTokenizer.from_pretrained(model_trans) File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\transformers\tokenization_utils_base.py", line 1947, in from_pretrained File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\transformers\utils\hub.py", line 430, in cached_file resolved_file = hf_hub_download( File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\huggingface_hub\utils_validators.py", line 110, in _inner_fn validate_repo_id(arg_value) File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\huggingface_hub\utils_validators.py", line 164, in validate_repo_id raise HFValidationError( huggingface_hub.utils.validators.HFValidationError: Repo id must use alphanumeric chars or '-', '', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: '/trans'. PS D:\AI> python .\RunProject.py 2023-12-09 22:39:19.498167: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable
TF_ENABLE_ONEDNN_OPTS=0. WARNING:tensorflow:From C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.WARNING:tensorflow:From C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\keras\src\backend.py:873: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
2023-12-09 22:39:47.733503: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
- Assistant
Bạn đang gặp hai vấn đề khác nhau khi chạy mã Python của mình:
-
Lỗi liên quan đến
MarianTokenizer.from_pretrained: Lỗi đầu tiên xuất hiện khi bạn cố gắng tải tokenizer sử dụngMarianTokenizer.from_pretrained. Có vẻ như giá trị bạn cung cấp chomodel_trans(có vẻ là '/trans') không phải là một ID repo hợp lệ. Bạn cần đảm bảo rằng ID repo này tuân theo các quy tắc được liệt kê trong thông báo lỗi:- Chỉ sử dụng các ký tự chữ và số (alphanumeric chars).
- Ký tự '-', '_', và '.' được phép, nhưng bạn không thể sử dụng '--' và '..'.
- Dấu '-' và '.' không thể là ký tự đầu tiên hoặc cuối cùng của tên.
- Độ dài tối đa là 96 ký tự.
Đây là cách khai báo ID repo một cách đúng đắn:
from transformers import MarianTokenizer model_trans = "HuggingFaceModelID" # Thay thế "HuggingFaceModelID" bằng ID model thực từ Model Hub tokenizertrans = MarianTokenizer.from_pretrained(model_trans)Trong đó
HuggingFaceModelIDlà ID của mô hình bạn muốn tải từ Hugging Face Model Hub. -
Cảnh báo liên quan đến TensorFlow:
-
Bạn nhận được cảnh báo rằng
tf.losses.sparse_softmax_cross_entropyđã lỗi thời và bạn nên sử dụngtf.compat.v1.losses.sparse_softmax_cross_entropythay thế. -
Cảnh báo thứ hai là cho
tf.get_default_graph, bạn lại nên sử dụngtf.compat.v1.get_default_graph. -
Thông báo cuối cùng về oneDNN và các hướng dẫn tối ưu hóa của CPU chỉ là để thông báo cho bạn biết rằng TensorFlow đang sử dụng các chỉ thị CPU hiện có để cải thiện hiệu suất.
Để giải quyết các cảnh báo lỗi thời, bạn cần cập nhật mã của mình:
# Sử dụng phiên bản tương thích cho sparse_softmax_cross_entropy tf.compat.v1.losses.sparse_softmax_cross_entropy(labels, logits) # Và cho get_default_graph tf.compat.v1.get_default_graph()Lưu ý rằng bạn cần phải tìm và cập nhật các dòng mã gọi những hàm này trong mã nguồn của bạn hoặc trong các thư viện bạn đang sử dụng.
-
Nếu bạn không chắc chắn về ID của mô hình bạn đang cố gắng tải, hãy kiểm tra trên Hugging Face Model Hub để tìm ID đúng. Mỗi mô hình trên Model Hub sẽ có một ID duy nhất mà bạn có thể sử dụng với
from_pretrained. -
- User
gọi tf.compat.v1.losses.sparse_softmax_cross_entropy(labels, logits)
Và cho get_default_graph
tf.compat.v1.get_default_graph() ở đâu
- Assistant
Các hàm
tf.compat.v1.losses.sparse_softmax_cross_entropyvàtf.compat.v1.get_default_graphlà các hàm trong TensorFlow 1.x được giữ lại trong không gian têntf.compat.v1của TensorFlow 2.x để duy trì khả năng tương thích ngược với mã cũ.Khi bạn nhận được cảnh báo về việc sử dụng hàm lỗi thời (deprecated), điều đó có nghĩa là mã bạn đang chạy hoặc một trong các thư viện bạn sử dụng đang dùng phiên bản cũ của hàm đó. Để khắc phục cảnh báo, bạn cần cập nhật các hàm đó đến phiên bản tương thích với TensorFlow 2.x, nếu mã đó là của bạn. Nếu mã đến từ thư viện bạn sử dụng, hãy kiểm tra xem có phiên bản mới hơn của thư viện đó không và nâng cấp lên nếu có.
Bạn không cần phải "gọi" các hàm nói trên ở một nơi nào đó một cách tùy ý; thay vào đó, bạn sẽ cập nhật các dòng code hiện tại nơi những cảnh báo này xuất hiện. Đây là ví dụ cách sửa đổi:
Trước đây, nếu có dòng code:
# Đây là cách gọi hàm lỗi thời trong TensorFlow 1.x loss = tf.losses.sparse_softmax_cross_entropy(labels, logits)Bạn cập nhật nó thành:
# Đây là cách tương thích với TensorFlow 2.x loss = tf.compat.v1.losses.sparse_softmax_cross_entropy(labels, logits)Tương tự, nếu bạn thấy dòng:
# Cách gọi hàm lỗi thời graph = tf.get_default_graph()Update nó thành:
# Cách cập nhật cho TensorFlow 2.x graph = tf.compat.v1.get_default_graph()Cả hai dòng code cập nhật này giờ sẽ tương thích với TensorFlow 2.x mà không gây ra cảnh báo.
Ensure như vậy bạn phải tìm chính xác nơi trong mã nguồn mà cảnh báo được sinh ra (thông thường ở các dòng chỉ đường dẫn file cùng số dòng trong thông báo lỗi hoặc warning) và thực hiện thay đổi tương ứng.
- User
ModuleNotFoundError: No module named 'tensorflow'
- Assistant
Lỗi
ModuleNotFoundError: No module named 'tensorflow'xảy ra khi Python không thể tìm thấy moduletensorflowtrong môi trường Python mà bạn đang làm việc. Điều này thường có nghĩa là TensorFlow chưa được cài đặt trong môi trường đó.Để giải quyết lỗi này, bạn cần cài đặt TensorFlow bằng cách sử dụng pip, công cụ quản lý gói package của Python. Bạn có thể mở command prompt, terminal, hoặc PowerShell (trên Windows), hoặc terminal (trên macOS hoặc Linux) và chạy lệnh sau để cài đặt TensorFlow:
pip install tensorflowNếu bạn đang sử dụng Python 3, bạn có thể cần sử dụng
pip3thay vìpip:pip3 install tensorflowĐôi khi, nếu bạn đang làm việc trong một môi trường ảo hoặc với một cài đặt Python đa phiên bản, bạn có thể phải sử dụng một lệnh pip cụ thể cho phiên bản Python đó, chẳng hạn:
python -m pip install tensorflow # hoặc python3 -m pip install tensorflowTrong một số trường hợp, bạn có thể muốn cài đặt phiên bản cụ thể của TensorFlow, đặc biệt là nếu bạn đang làm việc trên một dự án cần phiên bản không phải mới nhất:
pip install tensorflow==<version>Thay thế
<version>với số phiên bản cụ thể của TensorFlow mà bạn muốn cài đặt (ví dụ:2.4.0).Sau khi cài đặt TensorFlow, bạn có thể nhập nó vào script Python của mình bằng mã sau:
import tensorflow as tfĐảm bảo bạn đã cài đặt TensorFlow thành công trước khi thử import nó. Kiểm tra thông báo từ pip để đảm bảo việc cài đặt không gặp vấn đề gì.
- User
2023-12-09 23:07:33.862257: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable
TF_ENABLE_ONEDNN_OPTS=0. WARNING:tensorflow:From D:\AI.venv\lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.WARNING:tensorflow:From D:\AI.venv\lib\site-packages\keras\src\backend.py:873: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
2023-12-09 23:08:07.491136: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
- Assistant
These messages look familiar to the ones you posted earlier, and they each inform you about different aspects of your TensorFlow environment:
-
oneDNN Custom Operations Warning: This is an informational message stating that oneDNN custom operations are enabled, which might slightly affect numerical results due to the order in which calculations are performed. If you want to disable these optimizations, you can do so by setting the
TF_ENABLE_ONEDNN_OPTSenvironment variable to0. This is optional and only necessary if you want to ensure consistent floating-point computation at the cost of potentially reduced performance.To disable oneDNN optimizations, you can set the environment variable in your shell before running your Python script:
# On Unix-based systems export TF_ENABLE_ONEDNN_OPTS=0 # On Windows (Command Prompt) set TF_ENABLE_ONEDNN_OPTS=0 # On Windows (PowerShell) $env:TF_ENABLE_ONEDNN_OPTS="0"Or within your Python code before importing TensorFlow:
import os os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0' import tensorflow as tf -
Deprecated Function Warning: The message indicates that the functions
tf.losses.sparse_softmax_cross_entropyandtf.get_default_graphfrom TensorFlow 1.x are deprecated and suggests that you use their TensorFlow 2.x compatible versions (tf.compat.v1.losses.sparse_softmax_cross_entropyandtf.compat.v1.get_default_graph, respectively).If this deprecated function is in your code, you should update it. If it's coming from a library you are using, check if there is a newer version of that library that doesn't use the deprecated TensorFlow functions.
To resolve these warnings, find the code that calls these deprecated TensorFlow functions and replace them. For example:
Change this:
loss = tf.losses.sparse_softmax_cross_entropy(labels, logits) graph = tf.get_default_graph()To this:
loss = tf.compat.v1.losses.sparse_softmax_cross_entropy(labels, logits) graph = tf.compat.v1.get_default_graph() -
CPU Feature Guard Information: This message tells you that the TensorFlow binary is using your CPU's instruction set to optimize performance. It's just informational and doesn't require action unless you want to rebuild TensorFlow from sources to enable additional CPU instructions for further optimization, which is generally not needed for most users.
Make the necessary updates regarding the deprecated TensorFlow functions, and you should be good to go. The other messages are just informational and do not represent errors.
-
- User
là sao 2023-12-09 23:07:33.862257: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable
TF_ENABLE_ONEDNN_OPTS=0. WARNING:tensorflow:From D:\AI.venv\lib\site-packages\keras\src\losses.py:2976: The name tf.losses.sparse_softmax_cross_entropy is deprecated. Please use tf.compat.v1.losses.sparse_softmax_cross_entropy instead.WARNING:tensorflow:From D:\AI.venv\lib\site-packages\keras\src\backend.py:873: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
2023-12-09 23:08:07.491136: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE SSE2 SSE3 SSE4.1 SSE4.2 AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. All TF 2.0 model weights were used when initializing BlipForConditionalGeneration.
Some weights of BlipForConditionalGeneration were not initialized from the TF 2.0 model and are newly initialized: ['text_decoder.cls.predictions.decoder.bias'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
- Serving Flask app 'RunProject'
- Debug mode: on
- Assistant
Thông điệp này báo hiệu một vài thông tin và cảnh báo khác nhau liên quan đến việc bạn đang sử dụng TensorFlow để chạy một mô hình học máy:
-
oneDNN Custom Operations Information: Thông điệp này thông báo rằng các hoạt động tùy chỉnh oneDNN đang được bật. oneDNN là một thư viện tối ưu hóa giúp tăng tốc các tính toán liên quan đến Deep Learning. Tuy nhiên, việc này có thể gây ra sự khác biệt nhỏ trong kết quả tính toán do sai số làm tròn số dấu phẩy động từ việc thực hiện các phép tính theo thứ tự khác nhau. Nếu bạn muốn tắt tối ưu hóa oneDNN để có kết quả tính toán nhất quán hơn (mặc dù có thể ảnh hưởng đến hiệu suất), bạn có thể thiết lập biến môi trường
TF_ENABLE_ONEDNN_OPTSthành giá trị0. -
Deprecated Function Warnings: Hai cảnh báo tiếp theo thông báo rằng hai hàm
tf.losses.sparse_softmax_cross_entropyvàtf.get_default_graphtừ TensorFlow 1.x đã lỗi thời và khuyên bạn nên sử dụng các phiên bản tương thích với TensorFlow 2.x làtf.compat.v1.losses.sparse_softmax_cross_entropyvàtf.compat.v1.get_default_graph. Nếu bạn đang viết hoặc bảo trì mã nguồn, bạn cần cập nhật những dòng mã này theo các hàm thay thế được đề xuất. -
CPU Feature Guard Information: Thông điệp cuối cùng chỉ ra rằng TensorFlow đang được tối ưu hóa để sử dụng các chỉ thị CPU có sẵn, giúp cải thiện hiệu suất cho các hoạt động quan trọng về hiệu suất. Điều này chỉ mang tính thông tin và không đòi hỏi bạn phải làm gì cả, trừ khi bạn có kinh nghiệm và muốn tự mình xây dựng lại TensorFlow từ mã nguồn với các cờ trình biên dịch phù hợp để bật thêm các chỉ thị CPU khác.
Ngoài ra, thông điệp còn cho biết mô hình
BlipForConditionalGenerationđã sử dụng tất cả các trọng số từ mô hình TF 2.0 nhưng một số trọng số chưa được khởi tạo và cần được huấn luyện trước khi sử dụng cho dự đoán và suy luận.Cuối cùng, thông điệp đang báo rằng bạn đang chạy một ứng dụng Flask với chế độ debug bật. Flask là một framework web nhẹ cho Python, và chế độ debug cho phép bạn thấy các thông báo lỗi trực quan trong quá trình phát triển ứng dụng web của mình.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.