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

How does one update one model from another model? #905

Closed
hovinen opened this issue Jan 5, 2024 · 1 comment
Closed

How does one update one model from another model? #905

hovinen opened this issue Jan 5, 2024 · 1 comment

Comments

@hovinen
Copy link

hovinen commented Jan 5, 2024

I have two models, identical in structure, in which one is meant to be updated periodically from the other. Prior to #854 I did so using TensorCollection::iter_tensors as follows::

    fn update_model(&mut self) {
        struct Updater;
        impl TensorVisitor<f32, Cpu> for Updater {
            type Viewer = (ViewTensorRef, ViewTensorRef);
            type Err = <Cpu as HasErr>::Err;
            type E2 = f32;
            type D2 = Cpu;

            fn visit<S: dfdx::shapes::Shape>(
                &mut self,
                _: TensorOptions<S, f32, Cuda>,
                (model, model_training): <Self::Viewer as TensorViewer>::View<
                    '_,
                    Tensor<S, f32, Cuda>,
                >,
            ) -> Result<Option<Tensor<S, Self::E2, Self::D2>>, Self::Err> {
                let mut model = model.clone();
                model.axpy(1.0 - TAU, model_training, TAU);
                Ok(Some(model))
            }
        }
        self.model = TensorCollection::iter_tensors(&mut RecursiveWalker {
            m: (&self.model, &self.model_training),
            f: &mut Updater,
        })
        .unwrap()
        .unwrap();
    }

This functionality was removed in #854, and it's not clear to me what functionality replaces it.

How does one update a model now?

@hovinen
Copy link
Author

hovinen commented Mar 1, 2024

To answer my own question: this is supported through ModelEMA.

@hovinen hovinen closed this as completed Mar 1, 2024
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

1 participant