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

viewing connection fields of sparce/gpu models #635

Open
mjabri opened this issue Oct 11, 2015 · 9 comments
Open

viewing connection fields of sparce/gpu models #635

mjabri opened this issue Oct 11, 2015 · 9 comments

Comments

@mjabri
Copy link
Contributor

mjabri commented Oct 11, 2015

I now can train some sparse/gpu models and wanted to look at the results. What's the best way to view connection fields of sparce/gpu models? If nothing in place yet, any hints on how to get back the connection fields from the cusparse weight array?

@philippjfr
Copy link
Member

I remember briefly looking into this but I don't recall much so I can only comment generally on how the sparse representation is stored. Basically all the weights in a projection are stored in a single large sparse matrix, where each column represents one CF. So to view a single CF you should slice into the large matrix and then reshape the column to the size of the source sheet. Let me know if you run into any issues.

@mjabri
Copy link
Contributor Author

mjabri commented Oct 12, 2015

Thanks. I will try this. BTW I am finding the interactivity of the GUI (can run and watch and interrupt at same time) and the way .ty files can be ingested in notebooks simply too difficult to replace with the notebook. So if the problem of viewing legacy models (non-sparse) in latest topographica on github is not solvable, I may try to transplant the sparse/gpu parts into a version where the GUI is still working.

@mjabri
Copy link
Contributor Author

mjabri commented Oct 13, 2015

Was the idea of copying the connection fields weights from GPU back to host at end of simulation (mentioned in @Tasignotas thesis) implemented? I can see there the fields in GPUSparseCFProjection for (sparse) 'weights' and (cusparse.CSR) 'weights_gpu' and I am assuming the weights are still in weights_gpu after each run. So I am wondering whether a function for copying from weights_gpu to weights exists somewhether. Looked into gpu folder and could not find anything...

@jbednar
Copy link
Member

jbednar commented Oct 13, 2015

I don't think that they were ever copied out, but I could be mistaken.

Jim

On Tue, Oct 13, 2015 at 3:41 PM, M. Jabri [email protected] wrote:

Was the idea of copying the connection fields weights from GPU back to
host at end of simulation (mentioned in @Tasignotas
https://github.com/Tasignotas thesis) implemented? I can see there the
fields in GPUSparseCFProjection for (sparse) 'weights' and (cusparse.CSR)
'weights_gpu' and I am assuming the weights are still in weights_gpu after
each run. So I am wondering whether a function for copying from weights_gpu
to weights exists somewhether. Looked into gpu folder and could not find
anything...


Reply to this email directly or view it on GitHub
#635 (comment).

@mjabri
Copy link
Contributor Author

mjabri commented Oct 13, 2015

Ok, but how the receptive fields as produced on GPU would've been verified? I can see the activities with the gcal_sparse example with artificial patterns, but these response activities do not validate the learning is as expected.

@philippjfr
Copy link
Member

If the activities match by the end of the simulation then that verifies the learning by proxy. The chance of getting the same activity with different weights might as well be zero.

@mjabri
Copy link
Contributor Author

mjabri commented Oct 14, 2015

This is good for validation.

@mjabri mjabri closed this as completed Oct 14, 2015
@mjabri mjabri reopened this Oct 14, 2015
@mjabri
Copy link
Contributor Author

mjabri commented Oct 14, 2015

So seems reasonable to add a function to copy weights_gpu to weights for GPUSparseCFProjection which would be used when need to view and save the weights.

@mjabri
Copy link
Contributor Author

mjabri commented Oct 22, 2015

ok, here is a function that copies weights from gpu to cfs. Tested this on my old fork of topographica where i have transplanted the sparce/gpu stuff and it seems to work. I am not sure whether this is the most efficient way though.

from math import sqrt
from nmutils import info
import numpy as np

def cfs2cpu(in_conns):
    for c in in_conns:
        try:
            gw = c.weights_gpu
            m = gw.todense(to_cpu=True)
            if m is None:
                info('Could not get the dense matrix for connection {0}. Ignoring...'.format(c.name))
                continue
            rows,cols = m.shape
        except:
            import sys
            e = sys.exc_info()[0]
            info("Exception: \'{0}\' while coppying GPU weights of connection {1}. Ignoring.".\
                 format(e, c.name))
            continue
        info('Copying weights all {0} GPU weights of connection {1} to CF weights in flatcfs.'.format(rows,c.name))
        for i in xrange(rows):
            row = m[i]
            (s,) = row.shape
            s=sqrt(s)
            cf = row.reshape((s,s))
            r1,r2,c1,c2 = c.flatcfs[i].input_sheet_slice
            # Note below will not work as __set_weights of SparseConnectionField.
            # np.copyto(c.flatcfs[i].weights, cf[r1:r2,c1:c2])
            c.flatcfs[i].weights = cf[r1:r2,c1:c2].copy()
        del m

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