Dolphin icon indicating copy to clipboard operation
Dolphin copied to clipboard

demo代码无法在mac电脑上运行

Open wanthigh opened this issue 1 year ago • 5 comments

运行环境:macpro M2Pro芯片,Python3.10

完整日志如下: python demo_page_hf.py --model_path ./hf_model --input_path ./demo/page_imgs/page_1.jpeg --save_dir ./results

Config of the encoder: <class 'transformers.models.donut.modeling_donut_swin.DonutSwinModel'> is overwritten by shared encoder config: DonutSwinConfig { "attention_probs_dropout_prob": 0.0, "depths": [ 2, 2, 14, 2 ], "drop_path_rate": 0.1, "embed_dim": 128, "hidden_act": "gelu", "hidden_dropout_prob": 0.0, "hidden_size": 1024, "image_size": [ 1024, 1024 ], "initializer_range": 0.02, "layer_norm_eps": 1e-05, "mlp_ratio": 4.0, "model_type": "donut-swin", "num_channels": 3, "num_heads": [ 4, 8, 16, 32 ], "num_layers": 4, "patch_size": 4, "qkv_bias": true, "transformers_version": "4.47.0", "use_absolute_embeddings": false, "window_size": 8 }

Config of the decoder: <class 'transformers.models.mbart.modeling_mbart.MBartForCausalLM'> is overwritten by shared decoder config: MBartConfig { "activation_dropout": 0.0, "activation_function": "gelu", "add_cross_attention": true, "add_final_layer_norm": true, "attention_dropout": 0.0, "bos_token_id": 0, "classifier_dropout": 0.0, "d_model": 1024, "decoder_attention_heads": 16, "decoder_ffn_dim": 4096, "decoder_layerdrop": 0.0, "decoder_layers": 10, "dropout": 0.1, "encoder_attention_heads": 16, "encoder_ffn_dim": 4096, "encoder_layerdrop": 0.0, "encoder_layers": 12, "eos_token_id": 2, "forced_eos_token_id": 2, "init_std": 0.02, "is_decoder": true, "is_encoder_decoder": false, "max_position_embeddings": 4096, "model_type": "mbart", "num_hidden_layers": 12, "pad_token_id": 1, "scale_embedding": true, "tie_word_embeddings": false, "transformers_version": "4.47.0", "use_cache": true, "vocab_size": 73921 }

Total samples to process: 1

Processing ./demo/page_imgs/page_1.jpeg Legacy behavior is being used. The current behavior will be deprecated in version 5.0.0. In the new behavior, if both images and text are provided, the default value of add_special_tokens will be changed to False when calling the tokenizer if add_special_tokens is unset. To test the new behavior, set legacy=Falseas a processor call argument. Error processing ./demo/page_imgs/page_1.jpeg: "slow_conv2d_cpu" not implemented for 'Half'

最后,报错了"slow_conv2d_cpu" not implemented for 'Half'

wanthigh avatar May 23 '25 02:05 wanthigh

我这边运行成功的 Apple M3 Pro, python 3.13

python demo_page_hf.py --model_path ./hf_model --input_path ./demo/page_imgs/page_1.jpeg --save_dir ./results

完整的日志如下

Using a slow image processor as `use_fast` is unset and a slow processor was saved with this model. `use_fast=True` will be the default behavior in v4.52, even if the model was saved with a slow processor. This will result in minor differences in outputs. You'll still be able to use a slow processor with `use_fast=False`.

Total samples to process: 1

Processing ./demo/page_imgs/page_1.jpeg
Passing a tuple of `past_key_values` is deprecated and will be removed in Transformers v4.58.0. You should pass an instance of `EncoderDecoderCache` instead, e.g. `past_key_values=EncoderDecoderCache.from_legacy_cache(past_key_values)`.
Processing completed. Results saved to ./results

ericuni avatar May 23 '25 13:05 ericuni

Mac M2, Python3.11.11一样抱错,按提示需要将half()的方法移除

lindyer avatar May 26 '25 02:05 lindyer

我在windows电脑上也提这个错误,是怎么解决的啊

highyield3011 avatar May 30 '25 05:05 highyield3011

你只需要把demo_page_hf.py改一下,搜索里面的half()都改成float()就可以了。 这里不能跑是因为它默认用half precision(float16)为了在gpu上提高性能,但是pytorch在cpu上不支持几乎所有float16计算

Eleanoreee avatar Jun 05 '25 12:06 Eleanoreee

Image

patr1ckzhu avatar Jun 15 '25 04:06 patr1ckzhu