Code Monkey home page Code Monkey logo

Comments (4)

HuanyuZhang avatar HuanyuZhang commented on August 16, 2024

That is very weird. Could you share details about your "model" and your Opacus version information?

from opacus.

Han-Huaqiao avatar Han-Huaqiao commented on August 16, 2024

Thank you for your reply
The currently used version of opacus is 1.1.0

The model is defined as follows:

import torch
import numpy as np

class FeaturesLinear(torch.nn.Module):
    def __init__(self, field_dims, output_dim=1):
        super().__init__()
        self.fc = torch.nn.Embedding(sum(field_dims), output_dim)
        self.bias = torch.nn.Parameter(torch.zeros((output_dim, )))
        if np.__version__ < "1.24":
            self.offsets = np.array((0, *np.cumsum(field_dims)[:-1]), dtype=np.long)
        else:
            self.offsets = np.array((0, *np.cumsum(field_dims)[:-1]), dtype=np.int64)

    def forward(self, x):
        """
        :param x: Long tensor of size ``(batch_size, num_fields)``
        """
        x = x + x.new_tensor(self.offsets).unsqueeze(0)
        return torch.sum(self.fc(x), dim=1) + self.bias


class Model(torch.nn.Module):
    """
    A pytorch implementation of Logistic Regression.
    """
    def __init__(self, **kwargs):
        super().__init__()
        embedding_nums = 100000
        if 'embedding_nums' in kwargs:
            embedding_nums = int(kwargs['embedding_nums'])
        input_dim = 10
        if 'input_dim' in kwargs:
            input_dim = int(kwargs['input_dim'])
        self.linear = FeaturesLinear(field_dims=[embedding_nums for _ in range(input_dim)])

    def forward(self, x):
        """
        :param x: Long tensor of size ``(batch_size, num_fields)``
        """
        return torch.sigmoid(self.linear(x).squeeze(1))

from opacus.

HuanyuZhang avatar HuanyuZhang commented on August 16, 2024

I see. The version is too old. Could you please update to the latest version?
Right now, by functorch, Opacus could support any type of model.

from opacus.

Han-Huaqiao avatar Han-Huaqiao commented on August 16, 2024

Thanks for your reply, I will try a newer version of pacus.

from opacus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.