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

Is it possible to generate using CPU? #105

Open
xiankgx opened this issue May 10, 2021 · 2 comments
Open

Is it possible to generate using CPU? #105

xiankgx opened this issue May 10, 2021 · 2 comments

Comments

@xiankgx
Copy link

xiankgx commented May 10, 2021

with open('ffhq.pkl', 'rb') as f:
    G = pickle.load(f)['G_ema'].cuda()  # torch.nn.Module
z = torch.randn([1, G.z_dim]).cuda()    # latent codes
c = None                                # class labels (not used in this example)
img = G(z, c)                           # NCHW, float32, dynamic range [-1, +1]

I trained a custom model and was able to generate images using the above code. However, when I switch the device to CPU, I am faced with the following error:
RuntimeError: "slow_conv_transpose2d_out_cpu" not implemented for 'Half'

How can I fix it?

@JCBrouwer
Copy link

You can convert the generator to float and then run with force_fp32=True:

G = G.float()  # convert weights that are half precision to fp32
img = G(z, c, force_fp32=True)  # necessary to make sure intermediate casts to half aren't run

If you want to avoid having to type that every time you can also override the forward method like this:

import functools
G.forward = functools.partial(G.forward, force_fp32=True)

img = G(z, c)

@gtnbssn
Copy link

gtnbssn commented Jul 11, 2021

Look here for how to modify generate.py accordingly:

#54 (comment)

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

3 participants