Exemple #1
0
    def get_version(self, version: int = 0) -> Checkpoint:
        """
        Retrieve the checkpoint corresponding to the specified version of the
        model. If no version is specified the latest model version is returned.

        Arguments:
            version (int, optional): The model version number requested.
        """
        if version == 0:
            resp = api.get(
                self._master,
                "/api/v1/models/{}/versions/".format(self.name),
                {
                    "limit": 1,
                    "order_by": 2
                },
            )

            data = resp.json()
            latest_version = data["versions"][0]
            return Checkpoint.from_json({
                **latest_version["checkpoint"],
                "version":
                latest_version["version"],
                "model_name":
                data["model"]["name"],
            })
        else:
            resp = api.get(
                self._master,
                "/api/v1/models/{}/versions/{}".format(self.name, version))

        data = resp.json()
        return Checkpoint.from_json(data["version"]["checkpoint"],
                                    self._master)
Exemple #2
0
    def get_version(self, version: int = 0) -> Checkpoint:
        if version == 0:
            resp = api.get(
                self._master,
                "/api/v1/models/{}/versions/".format(self.name),
                {
                    "limit": 1,
                    "order_by": 2
                },
            )

            data = resp.json()
            latest_version = data["versions"][0]
            return Checkpoint.from_json({
                **latest_version["checkpoint"],
                "version":
                latest_version["version"],
                "model_name":
                data["model"]["name"],
            })
        else:
            resp = api.get(
                self._master,
                "/api/v1/models/{}/versions/{}".format(self.name, version))

        data = resp.json()
        return Checkpoint.from_json(data["version"]["checkpoint"],
                                    self._master)
Exemple #3
0
    def get_versions(
            self,
            order_by: ModelOrderBy = ModelOrderBy.DESC) -> List[Checkpoint]:
        """
        Get a list of checkpoints corresponding to versions of this model. The
        models are sorted by version number and are returned in descending
        order by default.

        Arguments:
            order_by (enum): A member of the ModelOrderBy enum.
        """
        resp = api.get(
            self._master,
            "/api/v1/models/{}/versions/".format(self.name),
            params={"order_by": order_by.value},
        )
        data = resp.json()

        return [
            Checkpoint.from_json(
                {
                    **version["checkpoint"],
                    "version": version["version"],
                    "model_name": data["model"]["name"],
                },
                self._master,
            ) for version in data["versions"]
        ]
Exemple #4
0
    def register_version(self, checkpoint_uuid: str) -> Checkpoint:
        """
        Creats a new model version and returns the
        :class:`~determined.experimental.Checkpoint` corresponding to the
        version.

        Arguments:
            checkpoint_uuid: The uuid to associated with the new model version.
        """
        resp = api.post(
            self._master,
            "/api/v1/models/{}/versions".format(self.name),
            body={"checkpoint_uuid": checkpoint_uuid},
        )

        data = resp.json()

        return Checkpoint.from_json(
            {
                **data["version"]["checkpoint"],
                "version":
                data["version"]["version"],
                "model_name":
                data["version"]["model"]["name"],
            },
            self._master,
        )
Exemple #5
0
 def get_checkpoint(self, uuid: str) -> Checkpoint:
     """
     Get the :class:`~determined.experimental.Checkpoint` representing the
     checkpoint with the provided UUID.
     """
     r = api.get(self._session._master,
                 "checkpoints/{}".format(uuid)).json()
     return Checkpoint.from_json(r, master=self._session._master)
Exemple #6
0
    def get_version(self, version: int = 0) -> Optional[Checkpoint]:
        """
        Retrieve the checkpoint corresponding to the specified version of the
        model. If the specified version of the model does not exist, an exception
        is raised.

        If no version is specified, the latest version of the model is
        returned. In this case, if there are no registered versions of the
        model, ``None`` is returned.

        Arguments:
            version (int, optional): The model version number requested.
        """
        if version == 0:
            resp = api.get(
                self._master,
                "/api/v1/models/{}/versions/".format(self.name),
                {
                    "limit": 1,
                    "order_by": 2
                },
            )

            data = resp.json()
            if data["modelVersions"] == []:
                return None

            latest_version = data["modelVersions"][0]
            return Checkpoint.from_json({
                **latest_version["checkpoint"],
                "model_version":
                latest_version["version"],
                "model_name":
                data["model"]["name"],
            })
        else:
            resp = api.get(
                self._master,
                "/api/v1/models/{}/versions/{}".format(self.name, version))

        data = resp.json()
        return Checkpoint.from_json(data["model_version"]["checkpoint"],
                                    self._master)
Exemple #7
0
    def get_versions(
            self,
            order_by: ModelOrderBy = ModelOrderBy.DESC) -> List[Checkpoint]:
        resp = api.get(
            self._master,
            "/api/v1/models/{}/versions/".format(self.name),
            params={"order_by": order_by.value},
        )
        data = resp.json()

        return [
            Checkpoint.from_json(
                {
                    **version["checkpoint"],
                    "version": version["version"],
                    "model_name": data["model"]["name"],
                },
                self._master,
            ) for version in data["versions"]
        ]