qiaochen / VeloAE

Low-dimensional Projection of Single Cell Velocity
MIT License
28 stars 1 forks source link

How to set core number? #3

Closed Roger-GOAT closed 2 years ago

Roger-GOAT commented 2 years ago

@qiaochen Hi, thank you for your help, I think I have almost done it. However, I used a shared server and the administrator found I used too many cores and kill my process. And the server has no GPU and it spends hours in the following step:

def expBaseAE(adata, exp_metrics):
    n_cells, n_genes = adata.X.shape
    in_dim = n_genes
    z_dim = args.z_dim
    h_dim = args.h_dim

    model = get_baseline_AE(in_dim, z_dim, h_dim).to(device)
    model = main_AE(args, model, save_name=f"baseAE_{args.model_name}")
    model.eval()
    with torch.no_grad():
        x = model.encoder(tensor_x)
        s = model.encoder(tensor_s)
        u = model.encoder(tensor_u)

        v = estimate_ld_velocity(s, u, device=device).cpu().numpy()
        x = x.cpu().numpy()
        s = s.cpu().numpy()
        u = u.cpu().numpy()

    adata = new_adata(adata, x, s, u, v, g_basis=args.nb_g_src)
    scv.tl.velocity_graph(adata, vkey='new_velocity')

    scv.pl.velocity_embedding_stream(adata, vkey="new_velocity", basis='X_umap', color='leiden',
                                    title="Baseline AutoEncoder",
                                    )  
    scv.tl.velocity_confidence(adata, vkey='new_velocity')
    exp_metrics['Baseline AutoEncoder'] = evaluate(adata, cluster_edges, 'leiden', "new_velocity")

expBaseAE(adata, exp_metrics)

Train Epoch: 100/20000  Loss: 58.325161
Train Epoch: 200/20000  Loss: 58.139397
Train Epoch: 300/20000  Loss: 57.977493
Train Epoch: 400/20000  Loss: 57.829357
Train Epoch: 500/20000  Loss: 57.699886
Train Epoch: 600/20000  Loss: 57.579666
Train Epoch: 700/20000  Loss: 57.464165
Train Epoch: 800/20000  Loss: 57.350796
Train Epoch: 900/20000  Loss: 57.239578

Could you point out how can I set the cores without GPU? Thank you very much~~

Roger-GOAT commented 2 years ago

torch.set_num_threads(20)

qiaochen commented 2 years ago

Thank you for finding the solution :)!