From 717ed7639c3ab3f3e7726a7e50b81d5bf2172a8a Mon Sep 17 00:00:00 2001 From: Nicola Dall'Asen Date: Wed, 13 Mar 2024 15:34:10 +0100 Subject: [PATCH] feat: automatically patch `collections` for >python 3.10 support (#21) Co-authored-by: Bo Liu --- cli_chat.py | 8 ++++++-- deepseek_vl/__init__.py | 13 +++++++++++++ deepseek_vl/models/siglip_vit.py | 6 +++--- deepseek_vl/serve/inference.py | 8 +++++--- pyproject.toml | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/cli_chat.py b/cli_chat.py index b121d9e..6bfb8f3 100644 --- a/cli_chat.py +++ b/cli_chat.py @@ -132,8 +132,12 @@ def chat(args, tokenizer, vl_chat_processor, vl_gpt, generation_config): while cur_img_idx < num_images: try: - image_file = input(f"({cur_img_idx + 1}/{num_images}) Input the image file path: ") - image_file = image_file.strip() # trim whitespaces around path, enables drop-in from for example Dolphin + image_file = input( + f"({cur_img_idx + 1}/{num_images}) Input the image file path: " + ) + image_file = ( + image_file.strip() + ) # trim whitespaces around path, enables drop-in from for example Dolphin except KeyboardInterrupt: print() diff --git a/deepseek_vl/__init__.py b/deepseek_vl/__init__.py index 8cb7640..09cc08c 100644 --- a/deepseek_vl/__init__.py +++ b/deepseek_vl/__init__.py @@ -16,3 +16,16 @@ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +# check if python version is above 3.10 +import sys + +if sys.version_info >= (3, 10): + print("Python version is above 3.10, patching the collections module.") + # Monkey patch collections + import collections + import collections.abc + + for type_name in collections.abc.__all__: + setattr(collections, type_name, getattr(collections.abc, type_name)) diff --git a/deepseek_vl/models/siglip_vit.py b/deepseek_vl/models/siglip_vit.py index 663783f..a93707b 100644 --- a/deepseek_vl/models/siglip_vit.py +++ b/deepseek_vl/models/siglip_vit.py @@ -338,9 +338,9 @@ class VisionTransformer(nn.Module): self.num_classes = num_classes self.global_pool = global_pool - self.num_features = ( - self.embed_dim - ) = embed_dim # num_features for consistency with other models + self.num_features = self.embed_dim = ( + embed_dim # num_features for consistency with other models + ) self.num_prefix_tokens = 1 if class_token else 0 self.num_prefix_tokens += reg_tokens self.num_reg_tokens = reg_tokens diff --git a/deepseek_vl/serve/inference.py b/deepseek_vl/serve/inference.py index c593e59..d92409c 100755 --- a/deepseek_vl/serve/inference.py +++ b/deepseek_vl/serve/inference.py @@ -50,9 +50,11 @@ def convert_conversation_to_prompts(conversation: Conversation): for i in range(0, len(messages), 2): prompt = { "role": messages[i][0], - "content": messages[i][1][0] - if isinstance(messages[i][1], tuple) - else messages[i][1], + "content": ( + messages[i][1][0] + if isinstance(messages[i][1], tuple) + else messages[i][1] + ), "images": [messages[i][1][1]] if isinstance(messages[i][1], tuple) else [], } response = {"role": messages[i + 1][0], "content": messages[i + 1][1]} diff --git a/pyproject.toml b/pyproject.toml index b084472..ad5905b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ authors = [{name = "DeepSeek-AI"}] license = {file = "LICENSE-CODE"} urls = {homepage = "https://github.com/deepseek-ai/DeepSeek-VL"} readme = "README.md" -requires-python = ">=3.8, <3.10" +requires-python = ">=3.8" dependencies = [ "torch>=2.0.1", "transformers>=4.38.2",