CannyLab / tsne-cuda

GPU Accelerated t-SNE for CUDA with Python bindings
BSD 3-Clause "New" or "Revised" License
1.81k stars 130 forks source link

tsne.fit_transform() prematurely ends before function return in a function call #124

Open ruyian opened 1 year ago

ruyian commented 1 year ago

I encountered an issue while working on my project and reported it on GitHub. The issue relates to a specific function call within my code.

I have a code snippet that includes a function call to fit_transform() as shown below:

def f():
    ...

    logger.info("Start TSNE")
    reduced_features = TSNE(n_components=2, perplexity=15, learning_rate=10).fit_transform(features)
    logger.info("Finish TSNE for features")

    ...
    return reduced_features

def main():
    ...
    f()
    logger.info("Finished dim reduction")

    g()

In this code excerpt, I've incorporated a call to fit_transform(). Utilizing a logger, I aim to document the execution progress. However, I observed that only the message "Start TSNE" is logged, while the subsequent log messages are conspicuously absent. Adding to the complexity, the function g() is unexpectedly invoked even though the preceding function f() should return a value that serves as an argument for g().

What's even more puzzling is that the program ends with g() triggering an exception, indicating that it is executed before the completion of f(). This behavior is not only unexpected and peculiar, given the dependency of g() on the return value of f().

I suspect that there might be an element of parallelization at play here. However, the complicating factor is that g() requires an argument that hinges on the output of f()'s t-SNE transformation.

I'm reaching out for insights into why this behavior is occurring and, more importantly, how to effectively address it. Your assistance in unraveling this conundrum would be immensely appreciated.