Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'cog' has no attribute 'Predictor' #58

Open
tianmianjiang opened this issue Nov 11, 2022 · 4 comments
Open

AttributeError: module 'cog' has no attribute 'Predictor' #58

tianmianjiang opened this issue Nov 11, 2022 · 4 comments

Comments

@tianmianjiang
Copy link

Hello, I have a problem. When I run the predict.py file, I get this error: AttributeError: module 'cog' has no attribute 'Predictor'. I've tried several things and it doesn't work. How can I solve this problem?
Thank you.

@bwest2397
Copy link

I dug into it a bit and the issue seems to be that they never pinned a version of cog, and so their code was written for a super outdated version of it. The current version of cog is 0.4.4, but from what I can tell the last version of cog that's compatible with their code is version 0.0.20. Unfortunately, pypi only has the following versions of cog: 0.4.4, 0.4.3, and 0.0.3. To install cog at version 0.0.20, I ran the following:

pip install -e "git+https://github.com/replicate/[email protected]#egg=cog&subdirectory=python/"

Once I did this, I was able to import everything from predict.py successfully.

@tianmianjiang
Copy link
Author

I dug into it a bit and the issue seems to be that they never pinned a version of cog, and so their code was written for a super outdated version of it. The current version of cog is 0.4.4, but from what I can tell the last version of cog that's compatible with their code is version 0.0.20. Unfortunately, pypi only has the following versions of cog: 0.4.4, 0.4.3, and 0.0.3. To install cog at version 0.0.20, I ran the following:

pip install -e "git+https://github.com/replicate/[email protected]#egg=cog&subdirectory=python/"

Once I did this, I was able to import everything from predict.py successfully.

Thank you very much indeed for your answer, I managed to solve the problem through your answer and help. After checking the information, I also found that the version of cog they were using was too low and caused a series of problems. So I used the latest version of cog and made the following changes to the code.
`class Predictor(BasePredictor):
def setup(self):
"""Load the model into memory to make running multiple predictions efficient"""
self.device = torch.device("cuda")
self.clip_model, self.preprocess = clip.load(
"ViT-B/32", device=self.device, jit=False
)
self.tokenizer = GPT2Tokenizer.from_pretrained("gpt2")

    self.models = {}
    self.prefix_length = 10
    for key, weights_path in WEIGHTS_PATHS.items():
        model = ClipCaptionModel(self.prefix_length)
        model.load_state_dict(torch.load(weights_path, map_location=CPU))
        model = model.eval()
        model = model.to(self.device)
        self.models[key] = model`

@rongtongxueya
Copy link

我深入研究了一下,问题似乎是他们从未固定过 的版本cog,因此他们的代码是为它的超级过时版本编写的。当前版本cog是 0.4.4,但据我所知,cog与其代码兼容的最后一个版本是 0.0.20 版本。不幸的是,pypi 只有以下版本cog:0.4.4、0.4.3 和 0.0.3。要安装cog版本 0.0.20,我运行了以下命令:

pip install -e "git+https://github.com/replicate/[email protected]#egg=cog&subdirectory=python/"

完成此操作后,我就能够成功导入 Predict.py 中的所有内容。

非常感谢您的回答,通过您的回答和帮助我成功解决了问题。经过查资料,我还发现他们使用的cog版本太低,导致了一系列问题。所以我使用了最新版本的cog并对代码进行了以下更改。 `class Predictor(BasePredictor): def setup(self): """将模型加载到内存中以提高运行多个预测的效率""" self.device = torch.device("cuda") self.clip_model, self.preprocess = Clip.load( "ViT-B/32", device=self.device, jit=False ) self.tokenizer = GPT2Tokenizer.from_pretrained("gpt2")

    self.models = {}
    self.prefix_length = 10
    for key, weights_path in WEIGHTS_PATHS.items():
        model = ClipCaptionModel(self.prefix_length)
        model.load_state_dict(torch.load(weights_path, map_location=CPU))
        model = model.eval()
        model = model.to(self.device)
        self.models[key] = model`

hi dude,I am still suffering from this problem, but I don't see any difference between the code you modified and the original one? Could you please give me some advice

@KNzzzzzzzzzz
Copy link

我深入研究了一下,问题似乎是他们从未固定过 的版本cog,因此他们的代码是为它的超级过时版本编写的。当前版本cog是 0.4.4,但据我所知,cog与其代码兼容的最后一个版本是 0.0.20 版本。不幸的是,pypi 只有以下版本cog:0.4.4、0.4.3 和 0.0.3。要安装cog版本 0.0.20,我运行了以下命令:

pip install -e "git+https://github.com/replicate/[email protected]#egg=cog&subdirectory=python/"

完成此操作后,我就能够成功导入 Predict.py 中的所有内容。

非常感谢您的回答,通过您的回答和帮助我成功解决了问题。经过查资料,我还发现他们使用的cog版本太低,导致了一系列问题。所以我使用了最新版本的cog并对代码进行了以下更改。 `class Predictor(BasePredictor): def setup(self): """将模型加载到内存中以提高运行多个预测的效率""" self.device = torch.device("cuda") self.clip_model, self.preprocess = Clip.load( "ViT-B/32", device=self.device, jit=False ) self.tokenizer = GPT2Tokenizer.from_pretrained("gpt2")

    self.models = {}
    self.prefix_length = 10
    for key, weights_path in WEIGHTS_PATHS.items():
        model = ClipCaptionModel(self.prefix_length)
        model.load_state_dict(torch.load(weights_path, map_location=CPU))
        model = model.eval()
        model = model.to(self.device)
        self.models[key] = model`

hi dude,I am still suffering from this problem, but I don't see any difference between the code you modified and the original one? Could you please give me some advice

Do you solve the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants